184 lines
3.7 KiB
TypeScript
184 lines
3.7 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 type typ_schreiber =
|
|
{
|
|
richtung : typ_richtung;
|
|
symbol : typ_symbol;
|
|
}
|
|
;
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_erstellen
|
|
(
|
|
richtung : typ_richtung,
|
|
symbol : typ_symbol
|
|
)
|
|
: typ_schreiber
|
|
{
|
|
return {
|
|
"richtung": richtung,
|
|
"symbol": symbol,
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function schreiber_erstellen_aktor
|
|
(
|
|
richtung : typ_richtung,
|
|
symbol : typ_symbol
|
|
)
|
|
: typ_aktor
|
|
{
|
|
return {"art": "schreiber", "angaben": schreiber_erstellen(richtung, symbol)};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_beispiel
|
|
(
|
|
)
|
|
: typ_schreiber
|
|
{
|
|
return schreiber_erstellen(0, 0);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function schreiber_richtung_lesen
|
|
(
|
|
schreiber : typ_schreiber
|
|
)
|
|
: typ_richtung
|
|
{
|
|
return schreiber.richtung;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
export function schreiber_symbol_lesen
|
|
(
|
|
schreiber : typ_schreiber
|
|
)
|
|
: typ_symbol
|
|
{
|
|
return schreiber.symbol;
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_drehen
|
|
(
|
|
schreiber : typ_schreiber,
|
|
inkrement : int = +1
|
|
)
|
|
: void
|
|
{
|
|
schreiber.richtung = richtung_addieren(schreiber.richtung, inkrement);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_verwenden
|
|
(
|
|
schreiber : typ_schreiber,
|
|
figur : typ_figur
|
|
)
|
|
: void
|
|
{
|
|
figur_schreiben(figur, schreiber.symbol);
|
|
figur_bewegen(figur, schreiber.richtung);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_exportieren
|
|
(
|
|
schreiber : typ_schreiber
|
|
)
|
|
: any
|
|
{
|
|
return {
|
|
"richtung": richtung_exportieren(schreiber.richtung),
|
|
"symbol": symbol_exportieren(schreiber.symbol),
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
function schreiber_importieren
|
|
(
|
|
roh : any
|
|
)
|
|
: typ_schreiber
|
|
{
|
|
return (
|
|
schreiber_erstellen
|
|
(
|
|
richtung_importieren(roh["richtung"]),
|
|
symbol_importieren(roh["symbol"])
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* @author kcf <vidofnir@folksprak.org>
|
|
*/
|
|
let wrap = (angaben => ({"art": "schreiber", "angaben": angaben}));
|
|
let unwrap = (aktor => aktor.angaben);
|
|
implementierung_aktor["schreiber"] =
|
|
{
|
|
"beispiel": () => wrap(schreiber_beispiel()),
|
|
"drehen": (aktor, inkrement) => schreiber_drehen(unwrap(aktor), inkrement),
|
|
"verwenden": (aktor, figur) => schreiber_verwenden(unwrap(aktor), figur),
|
|
"exportieren": (aktor) => ({"art": "schreiber", "angaben": schreiber_exportieren(aktor.angaben)}),
|
|
"importieren": (roh) => wrap(schreiber_importieren(roh)),
|
|
}
|
|
;
|
|
|
|
}
|
|
|
|
|