vtm/quelldatein/aufbau/figur.ts
Christian Fraß 13e34a6f42 sicherung
2017-11-09 14:06:35 +01:00

158 lines
3.2 KiB
TypeScript

/*
* Verrückte Turing-Maschinen — A turing complete game
* Copyright (C) 2016 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module mod_vtm_aufbau
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export class klasse_figur
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
private zustand : typ_zustand;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private band : Array<typ_symbol>;
/**
* @author kcf <vidofnir@folksprak.org>
*/
private stelle : typ_stelle;
/**
* @author kcf <vidofnir@folksprak.org>
*/
public constructor(band : Array<typ_symbol> = [], stelle : typ_stelle = stelle_null())
{
this.zustand = zustand_laufend;
this.band = band;
this.stelle = stelle;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public zustand_lesen() : typ_zustand
{
return this.zustand;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public band_lesen() : Array<typ_symbol>
{
return this.band;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public stelle_lesen() : typ_stelle
{
return this.stelle;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public bewegen(richtung : typ_richtung) : void
{
let summand : typ_stelle = stelle_von_richtung(richtung);
this.stelle = stelle_addieren(this.stelle, summand);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public schreiben(symbol : typ_symbol) : void
{
this.band.push(symbol);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public lesen() : schnittstelle_fehlermonade<typ_symbol>
{
if (this.band.length <= 0)
{
return (new klasse_nichts<typ_symbol>());
}
else
{
return (new klasse_schlicht<typ_symbol>(this.band[0]));
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public schieben() : void
{
if (this.band.length <= 0)
{
let meldung : string = "Band ist leer";
throw (new Error(meldung));
}
else
{
this.band.shift();
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public annehmen() : void
{
this.zustand = zustand_angenommen;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
public verwerfen() : void
{
this.zustand = zustand_abgelehnt;
}
}
}