git @ Cat's Eye Technologies Zzrk / rel_1_0_2007_0506 zzrk.zz
rel_1_0_2007_0506

Tree @rel_1_0_2007_0506 (Download .tar.gz)

zzrk.zz @rel_1_0_2007_0506raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
!! zzrk.zz - a simple text adventure written in "100% pure Zz"
!! Initial skeleton, Nov 21 2003 Chris Pressey
!! Minimally fleshed-out (50 pt) version, May 6 2007 Chris Pressey

!! Copyright (c)2003, 2007 Cat's Eye Technologies.  All rights reserved.
!!
!! Redistribution and use in source and binary forms, with or without
!! modification, are permitted provided that the following conditions
!! are met:
!!
!! 1. Redistributions of source code must retain the above copyright
!!    notices, this list of conditions and the following disclaimer.
!! 2. Redistributions in binary form must reproduce the above copyright
!!    notices, this list of conditions, and the following disclaimer in
!!    the documentation and/or other materials provided with the
!!    distribution.
!! 3. Neither the names of the copyright holders nor the names of their
!!    contributors may be used to endorse or promote products derived
!!    from this software without specific prior written permission. 
!!
!! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
!! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
!! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
!! FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
!! COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
!! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
!! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
!! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
!! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
!! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
!! POSSIBILITY OF SUCH DAMAGE.

!! ------------------- object system ---------------

!! define objects as a Zz type.

!! define the identity of an object.

/ident -> "obj" object^o { /return o as ident }

!! define equality on objects.

/$cond -> object^a "=" "=" object^b {
  /if obj a == obj b { /return 1 } else { /return 0 }
}
/$cond -> object^a "!" "=" object^b {
  /if obj a == obj b { /return 0 } else { /return 1 }
}

!! ----------- object definition definition -----------

/objects := {}                   !! list of all defined objects

/stat -> "object" ident^o {      !! "forward" declaration
  /object -> o { /return o }
}

                                 !! actual object declaration
/stat -> "object" ident^o string_e^sdesc0 string_e^desc0 ...
         object^n_exit0 object^s_exit0 object^e_exit0 object^w_exit0 ...
         string_e^takeable0 object^loc0 {
  /object   -> o              { /return o }
  /string_t -> "b_sdesc"    o { /return sdesc0 }
  /string_t -> "b_desc"     o { /return desc0 }
  /object   -> "b_n_exit"   o { /return n_exit0 }
  /object   -> "b_s_exit"   o { /return s_exit0 }
  /object   -> "b_e_exit"   o { /return e_exit0 }
  /object   -> "b_w_exit"   o { /return w_exit0 }
  /string_t -> "b_takeable" o { /return takeable0 }
  /object   -> "b_loc"      o { /return loc0 }
  /noun     -> sdesc0         { /return o }
  /objects  := objects &      { o }
}

/string_t -> "sdesc" object^o    { /return b_sdesc o }
/string_t -> "desc" object^o     { /return b_desc o }
/object   -> "n_exit" object^o   { /return obj b_n_exit o }
/object   -> "s_exit" object^o   { /return obj b_s_exit o }
/object   -> "e_exit" object^o   { /return obj b_e_exit o }
/object   -> "w_exit" object^o   { /return obj b_w_exit o }
/string_t -> "takeable" object^o { /return b_takeable o }
/object   -> "loc" object^o      { /return obj b_loc o }

!! ----------- object definitions proper -----------

object nowhere

object nowhere "nowhere" ...
  "You can't see anything like that here." ...
  nowhere nowhere nowhere nowhere "no" nowhere

object wall "wall" ...
  "You see nothing special." ...
  nowhere nowhere nowhere nowhere "no" nowhere

object square_room
object low_tunnel
object disused_armoury
object junction
object troll_room
object library
object treasure_room

object door

object player "yourself" ...
  "As beautiful as ever." ...
  nowhere nowhere nowhere nowhere "no" square_room

object square_room "Square Room" ...
  "You are in a square room.  A passage leads north; to the east is a door." ...
  low_tunnel wall door wall "no" nowhere

object door "door" ...
  "A heavy iron door, rusting with age." ...
  nowhere nowhere nowhere nowhere "no" square_room

object low_tunnel "Low Tunnel" ...
  "This is a low tunnel.  It heads north and south." ...
  disused_armoury square_room wall wall "no" nowhere

object key "key" ...
  "A small, shiny key." ...
  nowhere nowhere nowhere nowhere "yes" low_tunnel

object disused_armoury "Disused Armoury" ...
  "Dust covers eveything here.  A passage leads south." ...
  wall low_tunnel wall wall "no" nowhere

object coin "coin" ...
  "A standard, but nonetheless valuable, gold coin." ...
  nowhere nowhere nowhere nowhere "yes" low_tunnel

object sword "sword" ...
  "A finely-crafted implement of bloodletting." ...
  nowhere nowhere nowhere nowhere "yes" disused_armoury

object junction "Junction" ...
  "Rough-hewn passages lead off in all directions." ...
  troll_room treasure_room library square_room "no" nowhere

object jewel "jewel" ...
  "It is a dazzling blue gem, probably worth a pretty penny." ...
  nowhere nowhere nowhere nowhere "yes" junction

object troll_room "Troll Room" ...
  "Bloodstains and axe-gouges grace the walls." ...
  wall junction wall wall "no" nowhere

object troll "troll" ...
  "A nasty rubbery green sort with foul breath." ...
  nowhere nowhere nowhere nowhere "no" troll_room

object chest "chest" ...
  "Large and ornately carved out of cedar." ...
  nowhere nowhere nowhere nowhere "no" troll_room

object crown "crown" ...
  "A regal crown fashioned from gold, studded with topaz." ...
  nowhere nowhere nowhere nowhere "yes" chest

object sceptre "sceptre" ...
  "A tapered length of hardwood studded with jewels and crystals." ...
  nowhere nowhere nowhere nowhere "yes" treasure_room

object library "Library" ...
  "None of these books look like they've been disturbed for ages." ...
  wall wall wall junction "no" nowhere

object book "book" ...
  "Its leather binding is very dusty." ...
  nowhere nowhere nowhere nowhere "yes" library

object treasure_room "Treasure Room" ...
  "Unfortunely all that remains in most of the shelves are cobwebs." ...
  junction wall wall wall "no" nowhere


!! ----------------- object modifier utilities ------------

/stat -> "move" object^o "to" object^loc {
  /object -> "b_loc" o { /return loc }
}

!! ------------------- verbs ------------------


!! general statement -> command bridge.

/stat -> command^$

!! travel

/command -> go_verb^$ direction^d {
  /if d == north { /newloc = obj n_exit loc player }
  /if d == south { /newloc = obj s_exit loc player }
  /if d == east  { /newloc = obj e_exit loc player }
  /if d == west  { /newloc = obj w_exit loc player }
  /if newloc == wall {
    /print "There's a wall in the way."
  } else {
    /if newloc == door {
      /print "The door is closed and locked."
    } else {
      /if newloc == nowhere {
        /print "You can't go that way."
      } else {
        move player to newloc
        look
      }
    }
  }
}

/command -> direction^d { go d }

/go_verb -> "move"    {}
/go_verb -> "walk"    {}
/go_verb -> "go"      {}
/go_verb -> "travel"  {}

/direction -> "north" { /return north }
/direction -> "south" { /return south }
/direction -> "east"  { /return east }
/direction -> "west"  { /return west }
/direction -> "n"     { /return north }
/direction -> "s"     { /return south }
/direction -> "e"     { /return east }
/direction -> "w"     { /return west }

!! pick up

/command -> pickup_verb^$ visible_noun^n {
  /if n == nowhere {
    /print "You can't see any such thing."
  } else {
    /if n == sceptre {
      /print "Almost as if it were alive, it evades your grasp."
    } else {
      /if takeable n == "yes" {
        move n to player
        /print "Taken."
      } else {
        /print "You can't carry that!"
      }
    }
  }
}

/pickup_verb -> "get"        {}
/pickup_verb -> "grab"       {}
/pickup_verb -> "take"       {}
/pickup_verb -> "pick" "up"  {}

!! put down

/command -> putdown_verb^$ held_noun^n {
  /if n == nowhere {
    /print "You aren't carrying any such thing."
  } else {
    move n to loc player
    /print "Dropped." 
  }
}

/putdown_verb -> "drop"       {}
/putdown_verb -> "put" "down" {}

!! examine

/command -> examine_verb^v nearby_noun^n {
  /print desc n
}

/examine_verb -> "examine"    {}
/examine_verb -> "inspect"    {}
/examine_verb -> "look" "at"  {}

!! look

/command -> look_verb^$ {
  /print sdesc loc player
  /print desc loc player
  /foreach o in objects {
    /if o != player {
      /if loc o == loc player {
        /print "You can see a", sdesc o, "here."
      }
    }
  }
}

/look_verb -> "look" {}
/look_verb -> "l"    {}

!! inventory

/command -> inv_verb^$ {
  /inv_list := {}
  /foreach o in objects {
    /if loc o == player {
      /inv_list := inv_list & { o }
    }
  }
  /inv_length := inv_list.length
  /if inv_length == 0 {
    /print "You are empty-handed."
  } else {
    /print "You are carrying:"
    /foreach o in inv_list {
      /print "  a", sdesc o
    }
  }
}

/inv_verb -> "inventory"       {}
/inv_verb -> "inv"             {}
/inv_verb -> "i"               {}
/inv_verb -> "take" inv_verb^$ {}

!! score

/command -> "score" {
  /score_v := 0
  /foreach o in objects {
    /if loc o == player {
      /score_v := score_v + (score_of o)
    }
  }
  /print "Your score is",score_v,"points out of a possible 50."
  /if score_v == 50 {
    /print "Congratulations!  You won the adventure!"
  }
}

/$num_t -> "score_of" object^o {
  /sc := 0
  /if o == coin    { /sc :=  5 }
  /if o == jewel   { /sc := 10 }
  /if o == sceptre { /sc := 15 }
  /if o == crown   { /sc := 20 }
  /return sc
}

!! open

/command -> open_verb^$ nearby_noun^n {
  /if n == door {
    /if e_exit square_room != door {
      /print "It's already open."
    } else {
      /if loc key != player {
        /print "It's locked."
      } else {
        /object -> "b_e_exit" square_room { /return junction }
        /print "The door creaks open!"
      }
    }
  } else {
    /if n == chest {
      /if loc troll == loc player {
        /print "The troll guards it jealously."
      } else {
        /if loc crown != chest {
	  /print "It's already open."
	} else {
	  move crown to loc player
	  /print "You open the chest, revealing a beautiful crown."
	}
      }
    } else {
      /print "You can't open that!"
    }
  }
}

/open_verb -> "open"           {}
/open_verb -> "unlock"         {}

!! fight

/command -> fight_verb^$ visible_noun^n {
  /if n != troll {
    /print "Violence isn't the answer to this one."
  } else {
    /if loc sword != player {
      /print "You don't stand a chance bare-handed."
    } else {
      move troll to low_tunnel
      /print "You dodge and weave and valiantly deliver a stunning blow!"
      /print "The troll flees!"
    }
  }
}

/fight_verb -> "fight"          {}
/fight_verb -> "attack"         {}
/fight_verb -> "kill"           {}

!! read

/command -> read_verb^$ nearby_noun^n {
  /if n != book {
    /print "There's nothing written on it."
  } else {
    /print "Matters arcane and esoteric fill this volume."
    /print "You notice one word of magical essence in particular: YKZMNIFN"
    /command -> "ykzmnifn" {
      /if loc player == loc sceptre {
	move sceptre to player
        /print "The sceptre floats right into your hand!"
      } else {
        /print "Nothing happens here."
      }
    }
  }
}

/read_verb -> "read"       {}

!! ---------------------------- parse errors

/command -> noun^n {
  /print "But what do you want to do with the",n,"?"
}

!! It would be great if we could do this, but we can't.
!!
!! /command -> any^$ noun^$ {
!!  /print "I don't understand what you mean."
!! }

!! ---------------------------- nouns

/noun -> "the" noun^n { /return n }
/noun -> "a" noun^n   { /return n }
/noun -> "an" noun^n  { /return n }

/visible_noun -> noun^n {
  /if loc n == loc player {
    /return n
  }
  /if loc n != loc player {
    /return nowhere
  }
}

/held_noun -> noun^n {
  /if loc n == player {
    /return n
  }
  /if loc n != player {
    /return nowhere
  }
}

/nearby_noun -> noun^n {
  /if loc n == player || loc n == loc player {
    /return n
  }
  /if loc n != player && loc n != loc player {
    /return nowhere
  }
}

!! --------------------------- start

look