{"id":138,"date":"2012-04-24T16:38:41","date_gmt":"2012-04-24T14:38:41","guid":{"rendered":"https:\/\/herr-rau.de\/blogs\/inform\/?p=138"},"modified":"2012-04-28T11:11:29","modified_gmt":"2012-04-28T09:11:29","slug":"kapitel-4-veroeffentlichen","status":"publish","type":"post","link":"https:\/\/herr-rau.de\/blogs\/inform\/?p=138","title":{"rendered":"Kapitel 4: Eigene Klassen und Attribute"},"content":{"rendered":"<p>Wir wollen jetzt nur noch die sieben Gei\u00dflein in ihrem Haus haben. Au\u00dferdem soll der Wolf ja nur herein k\u00f6nnen, wenn er das richtige Kapuzenshirt an hat und wenn er die Kreide gefressen hat. <\/p>\n<h3>Zuerst die Gei\u00dflein<\/h3>\n<p>Man k\u00f6nnte nat\u00fcrlich sieben Mal das gleiche schreiben<\/p>\n<blockquote><p>The first kid is a thing in the Kid House. It is edible. The description is &#8220;A poor, helpless little kid. Baaa-ahh.&#8221;<\/p><\/blockquote>\n<p>Aber wir machen uns die Arbeit leichter und legen eine neue Klasse an, und zwar eine Unterklasse von <code>thing<\/code>. Das geht mit dem Schl\u00fcsselwort <code>a kind of<\/code>:<\/p>\n<blockquote><p>A goat-kid is a kind of thing. It is always edible. The description usually is &#8220;A poor, helpless little kid. Baaa-ahh.&#8221; The indefinite article is &#8220;the&#8221;.\n<\/p><\/blockquote>\n<p>Das mit dem Artikel brauchen wir, damit es dann nicht hei\u00dft: <code>You see a first kid<\/code>, sondern: <code>the first kid<\/code>.<\/p>\n<p>Dann geht es ein wenig schneller:<\/p>\n<blockquote><p>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.\n<\/p><\/blockquote>\n<p>Inform 7 ist dabei so schlau und versteht, dass das &#8220;s&#8221; in &#8220;goat-kids&#8221; ein Plural ist und die Klasse <code>goat-kid<\/code> gemeint ist.<\/p>\n<h3>Dann die Stimme des Wolfs<\/h3>\n<p>Ob der Wolf zu einem bestimmten Zeitpunkt das Kapuzenshirt tr\u00e4gt oder nicht, kann man leicht \u00fcberpr\u00fcfen. Ob der Wolf aber jemals die Kreide gefressen hat oder nicht, das merkt sich das Spiel standardm\u00e4\u00dfig nicht. Am einfachsten l\u00f6st man das \u00fcber ein Attribut des Wolfs, das angibt, in welchem Zustand er sich befindet &#8211; vor oder nach gefressener Kreide, beziehungsweise mit hoher oder tiefer Stimme.<\/p>\n<p>F\u00fcr den Anfang beschr\u00e4nken wir uns auf folgende <strong>Datentypen<\/strong>: <code>text<\/code>, <code>number <\/code>und <code>truth state<\/code>. (Entspricht: String, int, boolean.)<\/p>\n<p>Wir haben verschiedene M\u00f6glichkeiten:<\/p>\n<blockquote><p>The player has a number called frequency. The frequency of the player is 10.<\/p><\/blockquote>\n<blockquote><p>The player has a text called sound-of-voice. The sound-of-voice of the player is &#8220;low&#8221;.<\/p><\/blockquote>\n<blockquote><p>The player has a truth state called highness-of-voice. The highness-of-voice of the player is false.<\/p><\/blockquote>\n<p>Alternativ kann man &#8211; \u00e4hnlich wie in Java beim Aufz\u00e4hlungstyp <strong>Enum<\/strong> &#8211; Werte vorgeben. Zuerst werden die m\u00f6glichen Werte definiert (entsprechend der Enum-Definition):<\/p>\n<blockquote><p>Pitch is a kind of value. The pitches are high, middle and low.<\/p><\/blockquote>\n<p>Danach kann man ein Attribut von diesem Typ anlegen:<\/p>\n<blockquote><p>The player has a pitch called voice. The voice of the player is low.<\/p><\/blockquote>\n<p>Alternativ k\u00f6nnte man weniger objektorientiert arbeiten und eine <strong>globale Variable<\/strong> definieren, die keinem bestimmten Objekt zugeordnet ist:<\/p>\n<blockquote><p>Frequency is  a number that varies. The frequency is 12.<\/p><\/blockquote>\n<p>&#8212; Und zuletzt gibt es noch eine Abk\u00fcrzung, die man bei der Definition von Klassen verwenden kann:<\/p>\n<blockquote><p>A person can be good, bad or mediocre. People usually are good. [Inform wei\u00df, dass people der Plural von person ist]<\/p><\/blockquote>\n<p>Das geht schnell und hat lediglich den Nachteil, dass diese Art Attribut keinen Bezeichner hat, auf den man sich im Code beziehen k\u00f6nnte.<\/p>\n<p>Wenn wir uns f\u00fcr die Enum-L\u00f6sung entscheiden:<\/p>\n<blockquote><p>Pitch is a kind of value. The pitches are high, middle and low.<br \/>\nThe player has a pitch called voice. The voice of the player is low.<\/p><\/blockquote>\n<p>&#8211; dann lautet der gesamte Code bisher:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">\r\n&quot;The Wolf and the Seven Kids&quot; by Moritz.\r\n \r\nThe Wolf Cave is a room. &quot;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.&quot; West of the Wolf Cave is the Forest.\r\n \r\nThe Forest is a room. &quot;This place is very large and it is dark here. You can go north, east, south and west. You can hear birds singing.&quot; South of the Forest is the Marketplace. West of the Forest is the Entrance Area. North of the Forest is the River.\r\n \r\nThe River is a room. &quot;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.&quot;\r\n \r\nThe Marketplace is a room. &quot;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.&quot;\r\n \r\nThe Entrance Area is a room. &quot;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.&quot; West of the Entrance Area is the Kid House.\r\n \r\nThe Kid House is a room. &quot;A nice house. There is only one room, and the exit is west.&quot;\r\n \r\nThe red hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is &quot;This is a red hoodie. A hoodie is a sweater with a hood.&quot;\r\n \r\nThe black hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is &quot;This is a black hoodie. A hoodie is a sweater with a hood.&quot;\r\n \r\nThe white hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is &quot;This is a white hoodie. A hoodie is a sweater with a hood.&quot;\r\n \r\nThe piece of chalk is a thing. It is in the Marketplace. It is edible. The description is &quot;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.&quot;\r\n \r\nThe dripping cave ceiling is scenery in the Wolf Cave. The description is &quot;There are drops at the ceiling. The whole cave is very wet and you can hear the drops hitting the ground.&quot;\r\n \r\nThe trees are scenery in the Forest. The description is &quot;Lots of trees, some old, some new. Some have hearts cut into them.&quot; Understand &quot;tree&quot; as the trees.\r\n \r\nThe birds are scenery in the Forest. The description is &quot;Small bodies that hop from tree to tree.&quot;\r\n\r\nA goat-kid is a kind of thing. It is always edible. The description usually is &quot;A poor, helpless little kid. Baaa-ahh.&quot; The indefinite article is &quot;the&quot;. \r\n\r\nThe 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.\r\n\r\nPitch is a kind of value. The pitches are high, middle and low.\r\nThe player has a pitch called voice. The voice of the player is low.<\/pre>\n<p>Jetzt haben wir alle wichtigen Objekte angelegt. Aber noch kann der Wolf sich \u00fcberallhin frei bewegen, ob mit tiefer oder hoher Stimme, mit oder ohne Kapuzenshirt. Dieses Standardverhalten der Objekte muss im n\u00e4chsten Schritt angepasst werden.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wir wollen jetzt nur noch die sieben Gei\u00dflein in ihrem Haus haben. Au\u00dferdem soll der Wolf ja nur herein k\u00f6nnen, wenn er das richtige Kapuzenshirt an hat und wenn er die Kreide gefressen hat. Zuerst die Gei\u00dflein Man k\u00f6nnte nat\u00fcrlich &hellip; <a href=\"https:\/\/herr-rau.de\/blogs\/inform\/?p=138\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1305],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-schnellkurs-1"],"_links":{"self":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}