~ubuntu-branches/ubuntu/vivid/inform/vivid

« back to all changes in this revision

Viewing changes to tutor/house04.inf

  • Committer: Bazaar Package Importer
  • Author(s): Jan Christoph Nordholz
  • Date: 2008-05-26 22:09:44 UTC
  • mfrom: (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526220944-ba7phz0d1k4vo7wx
Tags: 6.31.1+dfsg-1
* Remove a considerable number of files from the package
  due to unacceptable licensing terms.
* Repair library symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
! ------------------------------------------------------------------------------
2
 
! Inform for New Writers
3
 
!
4
 
! The House - Version 4
5
 
!
6
 
! Last Modified: David Cornelson - 22-Jan-1998
7
 
!
8
 
! ------------------------------------------------------------------------------
9
 
 
10
 
Constant DEBUG;
11
 
 
12
 
Constant Story "The House";
13
 
 
14
 
Constant Headline
15
 
           "^Inform for New Writers^
16
 
             The House - Version 4^
17
 
             By New Writer (1998) - Last Compiled: 22-Jan-1998^";
18
 
 
19
 
Constant MAX_SCORE 100;
20
 
Serial "980122";
21
 
 
22
 
Release 2;
23
 
 
24
 
Include "Parser";
25
 
Include "VerbLib";
26
 
 
27
 
!-------------------------------------------------------------------------------
28
 
! Initialise
29
 
!
30
 
!-------------------------------------------------------------------------------
31
 
 
32
 
[ Initialise;
33
 
 
34
 
  location = Sidewalk;
35
 
 
36
 
];
37
 
 
38
 
[ PrintRank;
39
 
  print ", earning you the rank of ";
40
 
  if (score >= 100) "the greatest.";
41
 
  if (score >= 80) "above average.";
42
 
  if (score >= 60) "average.";
43
 
  if (score >= 40) "below average.";
44
 
  if (score >= 20) "the barely living.";
45
 
  "the living dead.";
46
 
];
47
 
 
48
 
! ----------------------------------------------------------------------------
49
 
! Locations
50
 
!
51
 
! In this section we will define our locations. These are "Objects" to Inform.
52
 
!
53
 
! ----------------------------------------------------------------------------
54
 
 
55
 
Object Sidewalk "Sidewalk"
56
 
    with  description
57
 
          "You are standing on the sidewalk in front of a house to the west.",
58
 
    w_to  Front_Porch,
59
 
    has   light;
60
 
 
61
 
Object Front_Porch "Front Porch"
62
 
    with  description
63
 
          "This is the front porch of the house. There are two doors
64
 
           leading inside. The door on the left leads west and the
65
 
           door on the right leads northwest.",
66
 
    e_to  Sidewalk,
67
 
    w_to  Left_Front_Door,
68
 
    in_to Left_Front_Door,
69
 
    nw_to Right_Front_Door,
70
 
    has   light;
71
 
 
72
 
Object -> Left_Front_Door "left front door"
73
 
    with    name "left" "front" "door",
74
 
            description
75
 
            "The left front door is made of brass.",
76
 
    when_open    "The left front door is open.",
77
 
    when_closed    "The left front door is closed.",
78
 
    door_to        Foyer,
79
 
    door_dir    w_to,
80
 
    has            static door openable;
81
 
 
82
 
Object Right_Front_Door "right front door"
83
 
    with    name "right" "front" "door",
84
 
            description
85
 
            "The right front door is made of wood.",
86
 
    when_open    "The right front door is open.",
87
 
    when_closed    "The right front door is closed.",
88
 
    door_to        [; if (location==Front_Porch) return Den; return Front_Porch; ],
89
 
    door_dir    [; if (location==Front_Porch) return nw_to; return se_to; ],
90
 
    found_in    Front_Porch Den,
91
 
    with_key    right_key,
92
 
    has            static door openable lockable locked;
93
 
 
94
 
!
95
 
! VERSION 4 - Cause and Effect. Things happen based on what a player does.
96
 
!
97
 
! In this version of The House, we're going to add an object, the rock, and
98
 
! a place where the rock is useful. Unlike version 3 where Inform provides
99
 
! a special 'door' object, we must provide our own logic to 'handle' the rock.
100
 
101
 
! To do this, we're going to use what are called 'code blocks'. A code block is a
102
 
! group of statements that combine to handle one particular piece of logic
103
 
!
104
 
! Code blocks contain a decision and/or a loop. A decision is handled by one of two
105
 
! Inform statements, the 'if' statement and the 'switch' statement. We'll talk about
106
 
! the 'switch' statement and 'loops' in later versions of The House.
107
 
!
108
 
! DECISION STATEMENTS
109
 
!
110
 
! THE 'if' STATEMENT
111
 
!
112
 
!    The 'if' statement contains a comparison of variables, numbers, and/or text that
113
 
!    provides a true or false result. Based on either result (true or false) another
114
 
!    code block is written to handle the decision.
115
 
!
116
 
!        For example:
117
 
!
118
 
!            if (1==1) {
119
 
!                print "True";
120
 
!            } else {
121
 
!                print "False";
122
 
!            }
123
 
!
124
 
!        In the above example, the word "True" will be printed because the comparison of
125
 
!        1 to 1 is a true statement, 1 certainly does equal 1. If we changed the comparison
126
 
!        to:
127
 
!
128
 
!            if (1==2) {
129
 
!                print "True";
130
 
!            } else {
131
 
!                print "False";
132
 
!            }
133
 
!
134
 
!        ...then "False" would be printed because 1 does not equal 2.
135
 
!
136
 
!        Here are some more examples of valid 'if' statements...
137
 
!
138
 
!            eggs=2;
139
 
!            if (eggs<2) {
140
 
!                print "You don't have enough eggs!";
141
 
!            } else {
142
 
!                print "You have enough eggs!";
143
 
!            }
144
 
!
145
 
!        The above 'if' statement asks if the variable 'eggs' is less than two. If the value
146
 
!        is less than two, print "You don't have enough eggs!", otherwise Inform will print
147
 
!        "You have two eggs, just enough!" (which is the case since we set the variable 'eggs'
148
 
!        to 2 before the 'if' statement).
149
 
!
150
 
!            eggs=2;
151
 
!            bacon=4;
152
 
!            if (eggs<2) {
153
 
!                print "You don't have enough eggs!";
154
 
!                if (bacon<4) {
155
 
!                    print "You don't have enough bacon either!";
156
 
!                } else {
157
 
!                    print "You have four strips of bacon though!";
158
 
!                }
159
 
!            } else {
160
 
!                print "You enough eggs!";
161
 
!                if (bacon<4) {
162
 
!                    print "You don't have enough bacon though!";
163
 
!                } else {
164
 
!                    print "You have four strips of bacon too!";
165
 
!                }
166
 
!            }
167
 
!
168
 
!        In the above example, things get more complicated. I'll rewrite it in english so
169
 
!        that you can understand what is happening. Many programmers start out writing
170
 
!        things in english and they call it 'pseudocode'.
171
 
!
172
 
!            set eggs to 2
173
 
!            set bacon to 4
174
 
!
175
 
!            if there are less than two eggs then
176
 
!                print "You don't have enough eggs!"
177
 
!                if there are less than four bacon then
178
 
!                    print "You don't have enough bacon either!"
179
 
!                else
180
 
!                    print "You have four strips of bacon though!"
181
 
!                end if
182
 
!            else
183
 
!                print "You enough eggs!"
184
 
!                if there are less than four bacon then
185
 
!                    print "You don't have enough bacon though!"
186
 
!                else
187
 
!                    print "You have four strips of bacon too!"
188
 
!                end if
189
 
!            end if
190
 
!
191
 
!    Questions:  Q: Why is there a double equal sign in the 'if' statement?
192
 
!
193
 
!                A: Inform will set variables with one equals sign "=" and compare them
194
 
!                   when you put two equals signs "==" together. This is important to
195
 
!                   remember and can cause a lot of 'bugs' in your code. Another exanple
196
 
!                   explaining this is:
197
 
!
198
 
!                        if (eggs=2) print "There are two eggs.";
199
 
!
200
 
!                   This statement will ALWAYS BE TRUE because eggs is being SET to 2, NOT
201
 
!                   compared.
202
 
!
203
 
!                Q: What are the squiggly brackets, '{' and '}', for?
204
 
!
205
 
!                A: They signify the beginning and end of an 'if' statement code block.
206
 
!                   You need them to group more than one statement together. The left
207
 
!                   squiggly bracket begin the code block and the right squiggly bracket
208
 
!                   ends the code block.
209
 
!
210
 
!                   NOTE: You only need the brackets if you have more than one statement
211
 
!                         in the resulting code block. Another example might be:
212
 
!
213
 
!                            if (eggs==2) {
214
 
!                                print "There are a pair of eggs.";
215
 
!                                bacon=4;
216
 
!                            }
217
 
!                            else
218
 
!                                print "There are ", eggs, " eggs.";
219
 
!
220
 
!                         In the above example, squiggly brackets were only needed for
221
 
!                         the 'true' code block because we have two statements where
222
 
!                         there is only one statement for the 'false' code block.
223
 
!
224
 
!                Q: What are the symbols for 'if' statement comparisons?
225
 
!
226
 
!                A: They are as follows:     ~=    not equal
227
 
!                                            ==    equal
228
 
!                                            <    less than
229
 
!                                            <=    less than or equal
230
 
!                                            >    greater than
231
 
!                                            >=    greater than or equal
232
 
!                                            &&    and
233
 
!                                            ||    or
234
 
!
235
 
!                    The '&&' and '||' symbols are used to combine comparisons. For example:
236
 
!
237
 
!                        if (eggs==2 && bacon==4) print "You have two eggs and four bacon!";
238
 
!
239
 
!                        if (eggs==2 || bacon==4) print "You have either 2 eggs or 4 bacon!";
240
 
!
241
 
 
242
 
!
243
 
! Okay, now let's apply our knowledge of the 'if' statement and write an embedded function
244
 
! that will handle our rock.
245
 
!
246
 
! We've placed the rock in the den, but we're going to put the action in the backyard
247
 
! which is a location we're adding in this version of The House. Skip down by the kitchen for
248
 
! more...
249
 
!
250
 
 
251
 
 
252
 
Object Den "Den"
253
 
    with    description
254
 
            "You are in the den of the house.",
255
 
    se_to   Right_Front_Door,
256
 
    out_to  Right_Front_Door,
257
 
    has     light;
258
 
 
259
 
!
260
 
! This is our rock object.
261
 
!
262
 
! We've added the property 'before' with the arguments 'PutOn','Insert', and
263
 
! 'ThrowAt:'. When the rock is thrown at or in anything, this function is executed.
264
 
!
265
 
! In this case, the object being thrown, rock or keys, is the value of the Inform
266
 
! variable 'noun'. If noun equals the object 'Rock', then the true code block is
267
 
! executed, otherwise the false code block is executed.
268
 
!
269
 
! Q: Why is the statement 'rtrue' placed at the end of both code blocks?
270
 
!
271
 
! A: Normally, the Inform parser handles the action of an object being thrown at
272
 
!    something else. This is the default processing. If you throw the 'right key'
273
 
!    around The House or at the pond, you'll see the 'default' Inform processing.
274
 
!
275
 
!    Since we wanted special processing for the rock, we handled the actions on
276
 
!    our own through our code. But at the end of handling the thrown rock, we have
277
 
!    to let the Inform parser know that we took care of everything and not to do
278
 
!    anything.
279
 
!
280
 
!    If we return true, Inform understands and leaves everything alone.
281
 
!    If we return false, Inform will execute the default processing.
282
 
!
283
 
!    By the way, rtrue and rfalse are shortcuts to the statements:
284
 
!
285
 
!       return true;
286
 
!       return false;
287
 
!
288
 
!
289
 
! Q: Why is the variable 'second' being compared to the object name 'Pond'?
290
 
!
291
 
! A: The variable 'second' is an Inform variable set to the second noun of
292
 
!    of a players statement. For example:
293
 
!
294
 
!           > THROW ROCK AT POND
295
 
!
296
 
!    In this statement, 'rock' is the first noun and Inform determines the object
297
 
!    value for 'rock' and sets the variable 'noun' to that value. For the noun
298
 
!    'pond', Inform determines the object value and sets this in the variable
299
 
!    'second'.
300
 
!
301
 
! Q: Why is '(the)' before 'second' in the print statement below?
302
 
!
303
 
! A: This is to force Inform to print the article 'the' before the word. In any
304
 
!    object, you can define the article property with a value, such as "the",
305
 
!    "your", "an", or "some", so that Inform understands how to refer to the
306
 
!    object in sentences.
307
 
!
308
 
 
309
 
Object -> Rock "rock"
310
 
    with    name "rock",
311
 
            description
312
 
            "It's smooth and flat, perfect for skipping in a pond.",
313
 
    before  [;  Insert,PutOn,ThrowAt:
314
 
                    if (second==Pond) {
315
 
                        print "The rock skips across the water several times and sinks.
316
 
                               Amazingly, after a few moments, the rock washes up at
317
 
                               your feet. Wow, what an undertow!^";
318
 
                        move Rock to Backyard;
319
 
                        rtrue;
320
 
                        !
321
 
                        ! Replace rock so that player can try it again....
322
 
                        !
323
 
                     } else {
324
 
                         print "You throw the rock at ",(the) second, " and bounces
325
 
                                back into your stomach. Ouch! That hurt.^";
326
 
                        rtrue;
327
 
                     }
328
 
            ];
329
 
 
330
 
Object Foyer "Foyer"
331
 
    with  description
332
 
          "You are standing in the foyer of the house. It seems as though
333
 
           you can go up a staircase, northwest, or back out the front
334
 
           door to the east.",
335
 
    out_to Front_Porch,
336
 
    e_to   Front_Porch,
337
 
    nw_to  Hallway,
338
 
    u_to   Upper_Hallway,
339
 
    has    light;
340
 
 
341
 
Object Hallway "Hallway"
342
 
    with   description
343
 
           "You are in the hallway on the first floor of the house. The
344
 
            foyer is southeast and the kitchen is west of here.",
345
 
    se_to  Foyer,
346
 
    w_to   Kitchen,
347
 
    has    light;
348
 
 
349
 
!
350
 
! We've added out_to and w_to for a connection to the backyard as well as
351
 
! changing the description to help the player know what's going on.
352
 
!
353
 
 
354
 
Object Kitchen "Kitchen"
355
 
    with   description
356
 
           "This is the kitchen of the house. A hallway can be seen to the
357
 
            east and an open doorway to the west leads out to the backyard.",
358
 
    e_to    Hallway,
359
 
    w_to    Backyard,
360
 
    out_to    Backyard,
361
 
    has        light;
362
 
 
363
 
!
364
 
! This is our new location. Notice we added the name "yard" in case the player
365
 
! abbreviates their commands.
366
 
!
367
 
Object Backyard "Backyard"
368
 
    with    name "yard",
369
 
            description
370
 
            "This is the backyard behind the house. There is a pond here.",
371
 
    e_to    Kitchen,
372
 
    in_to    Kitchen,
373
 
    has        light;
374
 
 
375
 
!
376
 
! This is where we plan to use the rock....
377
 
!
378
 
 
379
 
Object -> Pond "pond"
380
 
    with    name "pond" "water",
381
 
            description
382
 
            "It's a small pond, but wide enough to skip rocks.",
383
 
    has        static concealed container open;
384
 
 
385
 
Object Upper_Hallway "Upper Hallway"
386
 
    with   description
387
 
           "This is the second floor hallway. Rooms can be seen north and
388
 
            south and a staircase leads down.",
389
 
    n_to   North_Bedroom,
390
 
    s_to   South_Bedroom,
391
 
    d_to   Foyer,
392
 
    has    light;
393
 
 
394
 
Object North_Bedroom "North Bedroom"
395
 
    with   description
396
 
           "This is a bedroom on the north side of the house.",
397
 
    s_to   Upper_Hallway,
398
 
    has    light;
399
 
 
400
 
!
401
 
! Added the article "the"...
402
 
!
403
 
Object -> right_key "right key" with name "right" "key", article "the";
404
 
 
405
 
Object South_Bedroom "South Bedroom"
406
 
    with   description
407
 
           "This is a bedroom on the south side of the house.",
408
 
    n_to   Upper_Hallway,
409
 
    has    light;
410
 
 
411
 
! ----------------------------------------------------------------------------
412
 
! Grammar
413
 
!
414
 
! The grammar section includes the file "Grammar" and will later include
415
 
! extensions to the standard grammar library.
416
 
!
417
 
! ----------------------------------------------------------------------------
418
 
 
419
 
Include "Grammar";
420