Wir wollen jetzt nur noch die sieben Geißlein in ihrem Haus haben. Außerdem soll der Wolf ja nur herein können, wenn er das richtige Kapuzenshirt an hat und wenn er die Kreide gefressen hat.
Zuerst die Geißlein
Man könnte natürlich sieben Mal das gleiche schreiben
The first kid is a thing in the Kid House. It is edible. The description is “A poor, helpless little kid. Baaa-ahh.”
Aber wir machen uns die Arbeit leichter und legen eine neue Klasse an, und zwar eine Unterklasse von thing
. Das geht mit dem Schlüsselwort a kind of
:
A goat-kid is a kind of thing. It is always edible. The description usually is “A poor, helpless little kid. Baaa-ahh.” The indefinite article is “the”.
Das mit dem Artikel brauchen wir, damit es dann nicht heißt: You see a first kid
, sondern: the first kid
.
Dann geht es ein wenig schneller:
The first kid, the second kid, the third kid, the fourth kid, the fifth kid, the sixth kid and the seventh kid are goat-kids in the Kid House.
Inform 7 ist dabei so schlau und versteht, dass das “s” in “goat-kids” ein Plural ist und die Klasse goat-kid
gemeint ist.
Dann die Stimme des Wolfs
Ob der Wolf zu einem bestimmten Zeitpunkt das Kapuzenshirt trägt oder nicht, kann man leicht überprüfen. Ob der Wolf aber jemals die Kreide gefressen hat oder nicht, das merkt sich das Spiel standardmäßig nicht. Am einfachsten löst man das über ein Attribut des Wolfs, das angibt, in welchem Zustand er sich befindet – vor oder nach gefressener Kreide, beziehungsweise mit hoher oder tiefer Stimme.
Für den Anfang beschränken wir uns auf folgende Datentypen: text
, number
und truth state
. (Entspricht: String, int, boolean.)
Wir haben verschiedene Möglichkeiten:
The player has a number called frequency. The frequency of the player is 10.
The player has a text called sound-of-voice. The sound-of-voice of the player is “low”.
The player has a truth state called highness-of-voice. The highness-of-voice of the player is false.
Alternativ kann man – ähnlich wie in Java beim Aufzählungstyp Enum – Werte vorgeben. Zuerst werden die möglichen Werte definiert (entsprechend der Enum-Definition):
Pitch is a kind of value. The pitches are high, middle and low.
Danach kann man ein Attribut von diesem Typ anlegen:
The player has a pitch called voice. The voice of the player is low.
Alternativ könnte man weniger objektorientiert arbeiten und eine globale Variable definieren, die keinem bestimmten Objekt zugeordnet ist:
Frequency is a number that varies. The frequency is 12.
— Und zuletzt gibt es noch eine Abkürzung, die man bei der Definition von Klassen verwenden kann:
A person can be good, bad or mediocre. People usually are good. [Inform weiß, dass people der Plural von person ist]
Das geht schnell und hat lediglich den Nachteil, dass diese Art Attribut keinen Bezeichner hat, auf den man sich im Code beziehen könnte.
Wenn wir uns für die Enum-Lösung entscheiden:
Pitch is a kind of value. The pitches are high, middle and low.
The player has a pitch called voice. The voice of the player is low.
– dann lautet der gesamte Code bisher:
"The Wolf and the Seven Kids" by Moritz. The Wolf Cave is a room. "Here is your home. You got nearly everything in this cave that you need to invade the seven little kids. Light comes in from the west." West of the Wolf Cave is the Forest. The Forest is a room. "This place is very large and it is dark here. You can go north, east, south and west. You can hear birds singing." South of the Forest is the Marketplace. West of the Forest is the Entrance Area. North of the Forest is the River. The River is a room. "Here is a place where you can relax. Every time you did hard work, you can lie down next to the river and chill. A road leads south to a forest." The Marketplace is a room. "You should not stay here for too long, because the mother of the kids is often here to buy some food. If she sees you, she will bump the shit out of you. In the north, you can see the trees of the forest." The Entrance Area is a room. "Now you are in front of the house where the kids live. You have to go west to enter the house, or you can go east to the forest." West of the Entrance Area is the Kid House. The Kid House is a room. "A nice house. There is only one room, and the exit is west." The red hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a red hoodie. A hoodie is a sweater with a hood." The black hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a black hoodie. A hoodie is a sweater with a hood." The white hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a white hoodie. A hoodie is a sweater with a hood." The piece of chalk is a thing. It is in the Marketplace. It is edible. The description is "Here is some chalk. You can use it, to write on a blackboard. If you eat it, your voice will get temporarily high and female." The dripping cave ceiling is scenery in the Wolf Cave. The description is "There are drops at the ceiling. The whole cave is very wet and you can hear the drops hitting the ground." The trees are scenery in the Forest. The description is "Lots of trees, some old, some new. Some have hearts cut into them." Understand "tree" as the trees. The birds are scenery in the Forest. The description is "Small bodies that hop from tree to tree." A goat-kid is a kind of thing. It is always edible. The description usually is "A poor, helpless little kid. Baaa-ahh." The indefinite article is "the". The first kid, the second kid, the third kid, the fourth kid, the fifth kid, the sixth kid and the seventh kid are goat-kids in the Kid House. Pitch is a kind of value. The pitches are high, middle and low. The player has a pitch called voice. The voice of the player is low.
Jetzt haben wir alle wichtigen Objekte angelegt. Aber noch kann der Wolf sich überallhin frei bewegen, ob mit tiefer oder hoher Stimme, mit oder ohne Kapuzenshirt. Dieses Standardverhalten der Objekte muss im nächsten Schritt angepasst werden.