Automaten

Endliche Zustandsautomaten gehen ganz einfach. Bei einem Aufzug legt man die Räume fest. Die gehören noch gar nicht zum Aufzug, machen ihn aber erst interessant.

The Basement is a room. "A dark basement."
The Ground Floor is a room. "The ground floor. Looks tidy."
The First Floor is a room. "Nice view."

Dann kommt der Aufzug selber. Er kriegt zwei Knöpfe, die man drücken kann. Für jede mögliche auslösende Aktion legt man einen Knopf an. Die Knopf-Objekte sind dabei gar nicht nötig, die auslösende Aktionen kann man auch ohne sie haben.

The elevator is an enterable, transparent container in the basement. It is not portable. The description is "An elevator with an up and a down button."
The up button is a thing in the elevator. It is scenery. The description is "An arrow pointing upwards."
The down button is a thing in the elevator. It is scenery. The description is "An arrow pointing downwards."

Um aus dem Aufzug einen Automaten zu machen, kriegt er einen Zustand. Der Zustand ändert sich je nach Stockwerk.

The elevator has a number called zustand. The zustand of the elevator is 1.

Kernstück des Automaten ist die Zustandsübergangsfunktion. Die sieht in Inform so aus:

Instead of pushing the up button when the player is in the elevator:
	if the zustand of the elevator is 0:
		now the zustand of the elevator is 1;
		say "Going up. (Ground floor.)";
		now the elevator is in the ground floor;
	otherwise if the zustand of the elevator is 1:
		now the zustand of the elevator is 2;
		say "Going up. (First floor.)";
		now the elevator is in the first floor;
	otherwise:
		say "Nothing happens."

Instead of pushing the down button when the player is in the elevator:
	if the zustand of the elevator is 2:
		now the zustand of the elevator is 1;
		say "Going down. (Ground floor.)";
		now the elevator is in the ground floor;
	otherwise if the zustand of the elevator is 1:
		now the zustand of the elevator is 0;
		say "Going down. (Basement.)";
		now the elevator is in the basement;
	otherwise:
		say "Nothing happens."

Alternativ auch so:

Instead of pushing the up button when the zustand of the elevator is 0:
	now the zustand of the elevator is 1;
	say "Going up. (Ground floor.)";
	now the elevator is in the ground floor.
Instead of pushing the down button when the zustand of the elevator is 0:
	say "Nothing happens."

Instead of pushing the up button when the zustand of the elevator is 1:
	now the zustand of the elevator is 2;
	say "Going up. (First floor.)";
	now the elevator is in the first floor.
Instead of pushing the down button when the zustand of the elevator is 1:
	now the zustand of the elevator is 0;
	say "Going down. (Basement.)";
	now the elevator is in the basement.

Instead of pushing the up button when the zustand of the elevator is 2:
	say "Nothing happens.";
Instead of pushing the down button when the zustand of the elevator is 2:
	now the zustand of the elevator is 1;
	say "Going down. (Ground floor.)";
	now the elevator is in the ground floor.

Bei beiden Varianten kann man das Drücken des Knopfes abkürzen, so dass man nur noch up/down bzw. u/d eingeben muss:

Instead of going up when the player is in the elevator:
	Try pushing the up button.
Instead of going down when the player is in the elevator:
	Try pushing the down button.

Schreibe einen Kommentar