vtm/quelldatein/aufbau/figur.ts

199 lines
4.2 KiB
TypeScript
Raw Normal View History

2017-11-09 14:06:35 +01:00
/*
* 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
2018-03-26 10:42:58 +02:00
* it under the terms of the GNU General Public License as published by
2017-11-09 14:06:35 +01:00
* 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
2018-03-26 10:42:58 +02:00
* GNU General Public License for more details.
2017-11-09 14:06:35 +01:00
*
2018-03-26 10:42:58 +02:00
* You should have received a copy of the GNU General Public License
2017-11-09 14:06:35 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2017-11-08 11:30:34 +01:00
2018-03-26 10:42:58 +02:00
module mod_vtm
2017-11-08 11:30:34 +01:00
{
2018-03-26 10:42:58 +02:00
export module mod_aufbau
2017-11-08 11:30:34 +01:00
{
2018-03-26 10:42:58 +02:00
export module mod_figur
2017-11-08 15:05:06 +01:00
{
2018-03-26 10:42:58 +02:00
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type typ_figur =
{
zustand : mod_zustand.typ_zustand;
band : Array<mod_symbol.typ_symbol>;
stelle : mod_stelle.typ_stelle;
}
;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function erstellen
(
band : Array<mod_symbol.typ_symbol> = [],
stelle : mod_stelle.typ_stelle = mod_stelle.null_()
)
: typ_figur
{
return {
"zustand": mod_zustand.laufend,
"band": band,
"stelle": stelle,
};
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function zustand_lesen
(
figur : typ_figur
)
: mod_zustand.typ_zustand
{
return figur.zustand;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function band_lesen
(
figur : typ_figur
)
: Array<mod_symbol.typ_symbol>
{
return figur.band;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function stelle_lesen
(
figur : typ_figur
)
: mod_stelle.typ_stelle
{
return figur.stelle;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function bewegen
(
figur : typ_figur,
richtung : mod_richtung.typ_richtung
)
: void
{
let summand : mod_stelle.typ_stelle = mod_stelle.von_richtung(richtung);
figur.stelle = mod_stelle.addieren(figur.stelle, summand);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function schreiben
(
figur : typ_figur,
symbol : mod_symbol.typ_symbol
)
: void
{
figur.band.push(symbol);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function lesen
(
figur : typ_figur
)
: schnittstelle_fehlermonade<mod_symbol.typ_symbol>
{
if (figur.band.length <= 0)
{
return (new klasse_nichts<mod_symbol.typ_symbol>());
}
else
{
return (new klasse_schlicht<mod_symbol.typ_symbol>(figur.band[0]));
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function schieben
(
figur : typ_figur
)
: void
{
if (figur.band.length <= 0)
{
let meldung : string = "Band ist leer";
throw (new Error(meldung));
}
else
{
figur.band.shift();
}
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function annehmen
(
figur : typ_figur
)
: void
{
figur.zustand = mod_zustand.angenommen;
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function verwerfen
(
figur : typ_figur
)
: void
{
figur.zustand = mod_zustand.abgelehnt;
}
2017-11-08 15:05:06 +01:00
}
2018-03-26 10:42:58 +02:00
}
2018-03-26 10:42:58 +02:00
2017-11-08 11:30:34 +01:00
}