277 lines
7.1 KiB
TypeScript
277 lines
7.1 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_manifestation
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
*/
|
||
|
|
export class klasse_web_partie
|
||
|
|
extends klasse_manifestation<mod_vtm_aufbau.klasse_partie, void>
|
||
|
|
{
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
*/
|
||
|
|
private bereich : Element;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
*/
|
||
|
|
private intervall : schnittstelle_fehlermonade<any>;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
*/
|
||
|
|
public constructor(aufbau : mod_vtm_aufbau.klasse_partie, bereich : Element)
|
||
|
|
{
|
||
|
|
super(aufbau);
|
||
|
|
this.bereich = bereich;
|
||
|
|
this.intervall = (new klasse_nichts<any>());
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
* @implementation
|
||
|
|
*/
|
||
|
|
public darstellen() : void
|
||
|
|
{
|
||
|
|
// Zeichnung aktualisieren
|
||
|
|
{
|
||
|
|
let knoten_svg : mod_vtm_helfer.schnittstelle_xmlknoten = mod_vtm_manifestation.svg_wurzel
|
||
|
|
(
|
||
|
|
-4, -4,
|
||
|
|
+4, +4,
|
||
|
|
800, 800,
|
||
|
|
[new klasse_svg_partie(this.aufbau).darstellen()]
|
||
|
|
)
|
||
|
|
;
|
||
|
|
this.bereich.innerHTML = knoten_svg.darstellen();
|
||
|
|
}
|
||
|
|
// Status
|
||
|
|
{
|
||
|
|
let status : string;
|
||
|
|
switch (this.aufbau.modus_lesen())
|
||
|
|
{
|
||
|
|
case mod_vtm_aufbau.modus_initial:
|
||
|
|
{
|
||
|
|
status = "Rechts 'Testen' drücken zum Prüfen der Maschine";
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case mod_vtm_aufbau.modus_ungewiss:
|
||
|
|
{
|
||
|
|
status = "wird geprüft …";
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case mod_vtm_aufbau.modus_fehlerhaft:
|
||
|
|
{
|
||
|
|
status = "fehlerhaft :/";
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
case mod_vtm_aufbau.modus_korrekt:
|
||
|
|
{
|
||
|
|
status = "scheinbar korrekt :)";
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
{
|
||
|
|
let meldung : string = "unbehandelter Modus";
|
||
|
|
throw (new Error(meldung));
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
document.querySelector("#aufgabe_status").textContent = status;
|
||
|
|
}
|
||
|
|
// Knöpfe anzeigen/ausblenden
|
||
|
|
{
|
||
|
|
document.querySelector("#knoepfe").setAttribute
|
||
|
|
(
|
||
|
|
"class",
|
||
|
|
(
|
||
|
|
(this.aufbau.modus_lesen() === mod_vtm_aufbau.modus_initial)
|
||
|
|
? "initial"
|
||
|
|
: (
|
||
|
|
this.intervall.ist_schlicht()
|
||
|
|
? "testen_laufend"
|
||
|
|
: "testen_stehend"
|
||
|
|
)
|
||
|
|
)
|
||
|
|
)
|
||
|
|
;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author kcf <vidofnir@folksprak.org>
|
||
|
|
* @implementation
|
||
|
|
*/
|
||
|
|
public binden() : void
|
||
|
|
{
|
||
|
|
// Links-Klick
|
||
|
|
this.bereich.addEventListener
|
||
|
|
(
|
||
|
|
"click",
|
||
|
|
event =>
|
||
|
|
{
|
||
|
|
event.preventDefault();
|
||
|
|
if (this.aufbau.modus_lesen() === mod_vtm_aufbau.modus_initial)
|
||
|
|
{
|
||
|
|
let dom_feld : Element = event.target["closest"](".feld");
|
||
|
|
if (dom_feld == null)
|
||
|
|
{
|
||
|
|
console.info("-- kein Feld");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
let rel : string = dom_feld.getAttribute("rel")
|
||
|
|
let stelle : mod_vtm_aufbau.typ_stelle = mod_vtm_aufbau.stelle_von_hash(rel);
|
||
|
|
this.aufbau.welt_lesen().feld_wechseln(stelle);
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
console.info("-- nicht zur Bearbeitung freigegeben");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
)
|
||
|
|
;
|
||
|
|
// Rechts-Klick
|
||
|
|
this.bereich.addEventListener
|
||
|
|
(
|
||
|
|
"contextmenu",
|
||
|
|
event =>
|
||
|
|
{
|
||
|
|
event.preventDefault();
|
||
|
|
if (this.aufbau.modus_lesen() === mod_vtm_aufbau.modus_initial)
|
||
|
|
{
|
||
|
|
let dom_feld : Element = event.target["closest"](".feld");
|
||
|
|
if (dom_feld == null)
|
||
|
|
{
|
||
|
|
console.info("-- kein Feld");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
let rel : string = dom_feld.getAttribute("rel")
|
||
|
|
let stelle : mod_vtm_aufbau.typ_stelle = mod_vtm_aufbau.stelle_von_hash(rel);
|
||
|
|
this.aufbau.welt_lesen().feld_drehen(stelle);
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
console.info("-- nicht zur Bearbeitung freigegeben");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
)
|
||
|
|
;
|
||
|
|
// Testen
|
||
|
|
document.querySelector("#knopf_testen").addEventListener
|
||
|
|
(
|
||
|
|
"click",
|
||
|
|
event =>
|
||
|
|
{
|
||
|
|
this.intervall = (
|
||
|
|
new klasse_schlicht<any>
|
||
|
|
(
|
||
|
|
setInterval
|
||
|
|
(
|
||
|
|
() =>
|
||
|
|
{
|
||
|
|
this.aufbau.fortfahren();
|
||
|
|
let modus : mod_vtm_aufbau.typ_modus = this.aufbau.modus_lesen();
|
||
|
|
if (modus <= 1)
|
||
|
|
{
|
||
|
|
// nichts tun
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (this.intervall.ist_schlicht())
|
||
|
|
{
|
||
|
|
clearInterval(this.intervall.lesen());
|
||
|
|
this.intervall = (new klasse_nichts<int>());
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
let meldung : string = "kein Intervall gesetzt";
|
||
|
|
console.warn(meldung);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
,
|
||
|
|
500
|
||
|
|
)
|
||
|
|
)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
)
|
||
|
|
;
|
||
|
|
// Anhalten
|
||
|
|
document.querySelector("#knopf_anhalten").addEventListener
|
||
|
|
(
|
||
|
|
"click",
|
||
|
|
event =>
|
||
|
|
{
|
||
|
|
if (this.intervall.ist_schlicht())
|
||
|
|
{
|
||
|
|
clearInterval(this.intervall.lesen());
|
||
|
|
this.intervall = (new klasse_nichts<int>());
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
let meldung : string = "kein Intervall gesetzt";
|
||
|
|
console.warn(meldung);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
)
|
||
|
|
;
|
||
|
|
// Bearbeiten
|
||
|
|
document.querySelector("#knopf_bearbeiten").addEventListener
|
||
|
|
(
|
||
|
|
"click",
|
||
|
|
event =>
|
||
|
|
{
|
||
|
|
if (this.intervall.ist_schlicht())
|
||
|
|
{
|
||
|
|
clearInterval(this.intervall.lesen());
|
||
|
|
this.intervall = (new klasse_nichts<int>());
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// nichts tun
|
||
|
|
}
|
||
|
|
this.aufbau.zuruecksetzen();
|
||
|
|
this.darstellen();
|
||
|
|
}
|
||
|
|
)
|
||
|
|
;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|