Inventory This is the complete source code of the example game Alice3.inf.
Back to List
Complete
Browsing Alice3.inf
001 ! Through the Looking-Glass
002 ! An Inform tutorial by Gareth Rees
003 ! All rights given away
004 ! Version 3
005
006 Constant Story "THROUGH THE LOOKING GLASS";
007 Constant Headline "^An Interactive Tutorial^by Gareth Rees^";
008 Constant DEBUG;
009
010 ! Possible values for a kitten's state property:
011
012 Constant HELD_STATE = 0; ! Being held
013 Constant QUEEN_STATE = 1; ! Playing with the Red Queen
014 Constant WOOL_STATE = 2; ! Playing with the worsted
015 Constant CHAIR_STATE = 3; ! In the way of the chair
016
017 Include "parser";
018 Include "verblib";
019 Include "grammar";
020
021 [ Initialise;
022 location = Drawing_Room;
023 StartDaemon(white_kitten);
024 StartDaemon(black_kitten);
025 print "^^^^^It's a cold winter day outside, but in the
026 looking-glass house it's summer. All you need to do is
027 pretend there's a way of getting through into it
028 somehow...^^";
029 ];
030
031 [ Inside x y;
032 do {
033 x = parent(x);
034 } until (x == 0 or y);
035 if (x == 0) rfalse;
036 ];
037
038 [ UntangleSub; "What curious ideas you have!"; ];
039
040 [ ReflectSub;
041 if (second ~= mirror) "What a strange idea!";
042 if (noun == hearth or mirror || (player notin mantelpiece &&
043 player notin armchair))
044 "You can't see that in the looking-glass.";
045 print "The looking-glass ";
046 if (noun == player) print "Alice";
047 else print (name) noun;
048 if (player in mantelpiece) " looks very misty and blurred.";
049 print " looks just like the real ";
050 if (noun == player) print "Alice";
051 else print (name) noun;
052 " only all reversed, left for right.";
053 ];
054
055 Extend "look"
056 * "at" noun "in" noun -> Reflect;
057
058 Extend "examine"
059 * noun "in" noun -> Reflect;
060
061 Verb "roll" "untangle" "wind"
062 * noun -> Untangle
063 * "up" noun -> Untangle
064 * noun "up" -> Untangle;
065
066 Verb "pet" "stroke" = "rub";
067
068 Object Drawing_Room "Drawing room"
069 has light
070 with name "snow",
071 description "The gentle sound of snow against the window pane
072 suggests that it's cold outside, and you're glad to be
073 here in the warmth. The drawing-room is reflected in the
074 large looking-glass on the wall above the mantelpiece,
075 and a very comfortable room it is too, with a warm
076 hearth, a soft rug and an arm-chair that you can curl up
077 and sleep in.",
078 before [;
079 if (player notin Mantelpiece) rfalse;
080 Exit,Go:
081 if (noun == d_obj or out_obj)
082 "That's not the way to get down from a mantelpiece!";
083 Examine,Enter,ThrowAt,ThrownAt,Reflect: ;
084 default:
085 if (inp1 ~= 1 && noun ~= 0 && Inside(noun,mantelpiece) == 0)
086 "You can't reach ", (the) noun, " from up here.";
087 if (inp2 ~= 1 && second ~= 0 && Inside(second,mantelpiece) == 0)
088 "You can't reach ", (the) second, " from up here.";
089 ];
090
091 Object red_queen "red queen"
092 has female
093 with name "red" "queen",
094 describe [;
095 if (white_kitten.state == QUEEN_STATE
096 || black_kitten.state == QUEEN_STATE)
097 rtrue;
098 ],
099 description "She's a fierce little chess piece.",
100 after [;
101 Take:
102 if (white_kitten.state == QUEEN_STATE)
103 white_kitten.state = CHAIR_STATE;
104 if (black_kitten.state == QUEEN_STATE)
105 black_kitten.state = CHAIR_STATE;
106 PutOn,Transfer,Insert:
107 if (second == chess_board)
108 "Alone on the chess board, the red queen is monarch of
109 all she surveys.";
110 ];
111
112 Object chess_board "chess board" Drawing_Room
113 has supporter
114 with name "chess" "board" "checker" "chequer" "chessboard",
115 initial "An abandoned chess board lies on the floor.",
116 description "It's left here from the game you were playing
117 just now, but the pieces are all missing - the kittens
118 will insist on playing with them.";
119
120 Object hearth "hearth" Drawing_Room
121 has scenery
122 with name "hearth" "fire" "place" "fireplace";
123
124 Object rug "rug" Drawing_Room
125 has concealed static supporter enterable
126 ! general if you've found the red queen under it
127 with name "hearthrug" "hearth-rug" "rug" "indian" "arabian" "beautiful"
128 "soft",
129 description "It's a beautiful rug, made in some far off
130 country, perhaps India or Araby, wherever those might
131 be.",
132 before [;
133 Take: "The rug is much too large and heavy for you to carry.";
134 Push,Pull: "But a hearth-rug is meant to be next to the
135 hearth!";
136 LookUnder:
137 if (player in mantelpiece || player in armchair)
138 "You're unable to reach the rug from here.";
139 if (player in self)
140 "You try to lift up a corner of the rug, but fail. After
141 a while, you realise that this is because you are
142 standing on it. How curious the world is!";
143 if (self hasnt general) {
144 give self general;
145 move red_queen to player;
146 "You lift up a corner of the rug and, peering
147 underneath, discover the red queen from the chess
148 set.";
149 }
150 ];
151
152 Object armchair "arm-chair" Drawing_Room
153 has static concealed supporter enterable
154 ! general if its by the mantelpiece
155 with name "arm" "chair" "armchair" "arm-chair",
156 description [;
157 print "It's a huge arm-chair, the perfect place for a kitten
158 or a little girl to curl up in and doze. It has been
159 pushed over to the ";
160 if (self has general) "fireplace.";
161 "window.";
162 ],
163 before [ i;
164 Push,Pull:
165 if (player notin Drawing_Room)
166 "You'll have to get off ", (the) parent(player),
167 " first.";
168 if (white_kitten in player || black_kitten in player)
169 "Not with a kitten in your arms!";
170 if (white_kitten.state == CHAIR_STATE) i = white_kitten;
171 else if (black_kitten.state == CHAIR_STATE) i = black_kitten;
172 if (i ~= 0)
173 "You are about to start moving the chair when you
174 notice that ", (the) i, " is right in the way. It's a
175 good thing you spotted it, or you would have squashed
176 flat the poor little thing.";
177 if (self has general) {
178 give self ~general;
179 "You push the arm-chair away from the hearth.";
180 }
181 give self general;
182 "You push the arm-chair over to the hearth.";
183 Climb,Enter:
184 move player to armchair;
185 "You jump into the warm and comfortable arm-chair.";
186 Take: "The chair is so heavy you ca'n't carry it.";
187 ];
188
189 Object mantelpiece "mantelpiece" Drawing_Room
190 has concealed supporter enterable
191 with name "mantel" "mantelpiece",
192 description "It's higher off the ground than your head, but
193 it looks wide enough and sturdy enough to support you.",
194 before [;
195 Enter,Climb:
196 if (player notin armchair)
197 "The mantelpiece is much too high to climb up onto.";
198 if (armchair hasnt general)
199 "You can't reach the mantelpiece from here.";
200 if (children(player) > 0)
201 "Your hands are too full.";
202 move player to mantelpiece;
203 "You scramble up onto the mantelpiece.";
204 PutOn,LetGo:
205 if (player notin self && (player notin armchair ||
206 armchair hasnt general))
207 "The mantelpiece is so high that you can't reach.";
208 ];
209
210 Object mirror "looking-glass" Drawing_Room
211 has static concealed
212 with name "mirror" "looking" "glass" "looking-glass",
213 description [;
214 if (player in mantelpiece)
215 "Strangely, the glass is beginning to melt away,
216 just like a bright silvery mist.";
217 if (player in armchair)
218 "In the looking-glass you can see the drawing-room of
219 the looking-glass house. What you can see is very
220 much the same as this drawing-room, only all
221 reversed, left for right. But you are sure that out
222 of the corners of the glass, where you can't see, the
223 looking-glass world is quite different from yours.";
224 "In the looking-glass you can see the ceiling of the
225 drawing-room of the looking-glass house. It looks much
226 the same as the ceiling of your drawing-room.";
227 ],
228 before [;
229 if (action ~= ##Examine or ##ThrownAt or ##Reflect &&
230 player notin mantelpiece)
231 "You can't reach the looking-glass from where you're
232 standing.";
233 Touch,Pull,Push:
234 "Your hand goes right through the silvery mist!";
235 ThrownAt: "You don't want seven years' bad luck, do you?";
236 Enter:
237 ! Really, move Alice to the looking-glass house.
238 deadflag = 2;
239 "Your hand goes right through the silvery mist, and in
240 another moment the rest of you follows, and you are
241 through the glass...";
242 ];
243
244 Object worsted "ball of worsted" Drawing_Room
245 ! general if its in a tangle
246 with name "ball" "of" "worsted" "fine" "blue" "wool",
247 describe [;
248 if (white_kitten.state ~= WOOL_STATE &&
249 black_kitten.state ~= WOOL_STATE)
250 "^A discarded ball of worsted lies on the floor here.";
251 rtrue;
252 ],
253 description [;
254 if (self has general)
255 "It's in a terrible tangle. All that time you spent
256 rolling it up, and now look at it!";
257 "It's a ball of fine blue wool, all rolled up in preparation
258 for some embroidery.";
259 ],
260 before [;
261 Untangle:
262 give self ~general;
263 "You're as quick as can be at rolling up balls of wool,
264 though you say so yourself! Soon it's neat and tidy again.";
265 ],
266 after [;
267 Take:
268 if (white_kitten.state == WOOL_STATE)
269 white_kitten.state = CHAIR_STATE;
270 if (black_kitten.state == WOOL_STATE)
271 black_kitten.state = CHAIR_STATE;
272 ];
273
274 Object chess_pieces "chess pieces" Drawing_Room
275 has scenery
276 with parse_name [ w colour n;
277 w = NextWord();
278 if (w == 'white' or 'red') {
279 n ++;
280 colour = w;
281 w = NextWord();
282 }
283 if (w == 'pawn' or 'rook' or 'castle' ||
284 w == 'knight' or 'horse' or 'bishop' ||
285 w == 'king' || (w == 'queen' &&
286 (colour == 'white' || rug hasnt general))) return n + 1;
287 return 0;
288 ],
289 before [;
290 "Alas, that chess piece seems to be missing. Those
291 naughty kittens!";
292 ];
293
294 Object window "window" Drawing_Room
295 has scenery
296 with name "window" "pane",
297 description "Outside the window it's snowing gently, and you're
298 glad to be in here in the warmth.",
299 before [;
300 Open: "You wouldn't want to catch a chill, would you? Better
301 leave the window shut.";
302 Search: <<Examine self>>;
303 ];
304
305 Class Kitten
306 has animate
307 ! general if it's been described this turn
308 with parse_name [ w ok n;
309 do {
310 ok = 0;
311 w = NextWord();
312 if (w == 'kittens' or 'cats') {
313 ok = 1; n++; parser_action=##PluralFound;
314 }
315 if (w == 'kitten' or 'kitty' or 'cat' ||
316 w == ((self.&name)-->0)) {
317 ok = 1; n++;
318 }
319 } until (ok == 0);
320 return n;
321 ],
322
323 state CHAIR_STATE,
324
325 describe [ i;
326 switch (self.state) {
327 QUEEN_STATE:
328 "^A ", (name) self, " is playing with the red queen.";
329 WOOL_STATE:
330 "^A ", (name) self, " is playing with a ball of worsted.";
331 CHAIR_STATE:
332 if (self has general) rtrue;
333 if ((self.other_kitten).state == 3) {
334 i = self.other_kitten;
335 give i general;
336 "^Two kittens, one white and one black, are playing
337 together by the arm-chair.";
338 }
339 "^A ", (name) self, " is playing by the arm-chair.";
340 default: rtrue;
341 }
342 ],
343 description [;
344 "What a beautiful kitten ", (the) self, " is. Why,
345 it's quite definitely your favourite of the pair, and
346 much prettier than that naughty ",
347 (name) self.other_kitten, ".";
348 ],
349 life [;
350 Ask,Answer,Order:
351 print_ret (The) self, " twitches its whiskers and looks at
352 you with such a clever expression that you are certain it
353 understands every word you are saying.";
354 Kiss:
355 "You give ", (the) self, " a little kiss on its
356 nose, and it looks sweetly and demurely at you.";
357 Attack: "You would never do such a beastly thing to such
358 a defenceless little animal!";
359 Show:
360 print_ret (The) self, " bats a paw at ", (the) noun, ".";
361 Give,ThrowAt:
362 if (noun ~= red_queen or worsted) {
363 if (action == ##ThrowAt) {
364 move noun to Drawing_Room;
365 print "You toss ", (the) noun, " onto the floor, but ",
366 (the) self;
367 }
368 else print (The) self;
369 " just examines ", (the) noun,
370 " with a quizzical expression.";
371 }
372 print "You toss ", (the) noun, " onto the floor and ", (the) self;
373 if (self in player)
374 print " squirms out of your grasp and";
375 move noun to Drawing_Room;
376 move self to Drawing_Room;
377 print " scampers after it";
378 if (noun == worsted) {
379 give worsted general;
380 self.state = WOOL_STATE;
381 print ", quickly turning the neat ball into a tangle";
382 }
383 else self.state = QUEEN_STATE;
384 ".";
385 ],
386 before [;
387 Take:
388 if (self.other_kitten in player)
389 "You can't hold two kittens at once!";
390 self.state = HELD_STATE;
391 move self to player;
392 "You pick up ", (the) self,
393 ". What a beautiful creature it is!";
394 Touch, Rub: print_ret (The) self, " rubs its head against you and purrs softly.";
395 ],
396 after [;
397 Drop:
398 self.state = CHAIR_STATE;
399 move self to Drawing_Room;
400 print_ret (The) self, " squirms out of your arms and scampers
401 away.";
402 Transfer,PutOn,Insert:
403 self.state = CHAIR_STATE;
404 print (The) self, " jumps off ", (the) parent(self);
405 move self to Drawing_Room;
406 ", landing lightly on the floor before scampering away.";
407 ],
408 daemon [ i;
409 give self ~general;
410 self.this_kittens_turn = 1 - self.this_kittens_turn;
411 if (self.this_kittens_turn == false || random(3) == 2) rtrue;
412 new_line;
413 print (The) self;
414 switch (self.state) {
415 HELD_STATE:
416 switch(random(5)) {
417 1: " mews plaintively.";
418 2: " purrs quietly to itself.";
419 3: " purrs contentedly to itself.";
420 4: " rubs its ears against you.";
421 5: move self to Drawing_Room;
422 self.state = CHAIR_STATE;
423 " squirms out of your arms and scampers away.";
424 }
425 QUEEN_STATE:
426 switch (random(5)) {
427 1: " bats at the red queen with its paw.";
428 2: " stops playing and sits up, pretending to be
429 innocent of any kittenish tendancies.";
430 3: " knocks the red queen across the floor and chases
431 after it.";
432 4: " stops to wash itself.";
433 5: " bites the red queen and shakes it to make sure that
434 it's dead.";
435 }
436 WOOL_STATE:
437 give worsted general;
438 switch (random(5)) {
439 1: " bats at the ball of worsted with its paw.";
440 2: " pushes the ball of worsted across the floor and
441 chases after it.";
442 3: " leaps onto the ball of worsted and grapples bravely
443 with it.";
444 4: " jumps into the ball of worsted and gets tangled up
445 in a mess of threads.";
446 5: " stops playing and scratches its ears.";
447 }
448 CHAIR_STATE:
449 if ((self.other_kitten).state == CHAIR_STATE && random(2) == 1) {
450 i = random(5);
451 switch (i) {
452 1: print " chases after ";
453 2: print " jumps on top of ";
454 3: print " washes ";
455 4: print " scampers around the arm-chair and ";
456 5: print " bats at ";
457 }
458 print (the) self.other_kitten;
459 switch (i) {
460 1,3: ".";
461 2: " and they roll around on the floor.";
462 4: " chases after it.";
463 5: " with its paw.";
464 }
465 }
466 switch (random(5)) {
467 1: " scampers after a speck of dust.";
468 2: " rolls around on the floor.";
469 3: " sits up and washes its tail.";
470 4: " scratches its head on the arm-chair.";
471 5: " chases its tail.";
472 }
473 }
474 ];
475
476 Kitten white_kitten "white kitten" Drawing_Room
477 with name "white",
478 this_kittens_turn false,
479 other_kitten black_kitten;
480
481 Kitten black_kitten "black kitten" Drawing_Room
482 with name "black",
483 this_kittens_turn true,
484 other_kitten white_kitten;
Last updated 23 June 2004.
This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation.
Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.