(play).
You are in the cave-entrance. Exits: (north) Your command? north You are in the tunnel. Exits: (north west south) Monster: bat Your command? east You can't do that here. You are in the tunnel. Exits: (north west south) Monster: bat Your command? attack bat You swing...a hit! You killed it! You are in the tunnel. Exits: (north west south) Your command? west You are in the library. Exits: (east north) Treasure: book Your command? get book Done. You are in the library. Exits: (east north) Your command? north You are in the lair. Exits: (south east) Monster: dragon Treasure: hoard Your command? get hoard You can't do that with unfriendlies about. You are in the lair. Exits: (south east) Monster: dragon Treasure: hoard Your command? attack dragon You swing...a hit! It counterrattacks...a miss! You are in the lair. Exits: (south east) Monster: dragon Treasure: hoard Your command? attack dragon You swing...a hit! It counterrattacks...a miss! You are in the lair. Exits: (south east) Monster: dragon Treasure: hoard Your command? attack dragon You swing...a miss! It counterrattacks...a miss! You are in the lair. Exits: (south east) Monster: dragon Treasure: hoard Your command? attack dragon You swing...a hit! You killed it! You are in the lair. Exits: (south east) Treasure: hoard Your command? get hoard Done. You are in the lair. Exits: (south east) Your command? get funky There is no funky here. You are in the lair. Exits: (south east) Your command? quit Goodbye.
Every monster has a strength level -- the player's strength starts at 3. When the player attacks a monster (or vice versa), the attacker and target each roll a die and add it to their strength. If the attacker's total is greater, the defender loses a point of strength. When a creature's strength hits 0, it dies.
(define dungeon
(build-dungeon
(build-room 'cave-entrance
'((north . 1))
#f
#f)
(build-room 'tunnel
'((north . 3) (west . 2) (south . 0))
'(bat . 1)
#f)
(build-room 'library
'((east . 1) (north . 4))
#f
'book)
(build-room 'cathedral
'((west . 4) (south . 1))
#f
'sword)
(build-room 'lair
'((south . 2) (east . 3))
'(dragon . 3)
'hoard)))
Since we've separated the data from the program, we could create a different
adventure simply by specifying a different dungeon.
You will have to write the function build-room above.
It takes four arguments: the name of the room, the exits from the
room (an association list associating directions with indices of
other rooms), the monster in the room (either #f or a dotted pair of the
monster's name and strength), and the treature in the room (either #f
or a symbol).
The function build-dungeon assembles all the rooms into
some structure. A good choice is to:
(define build-dungeon vector)
play which takes no
arguments. This should start up a "read-eval-print" loop (e.g.,
another recursive function) which reads a command from the user,
handles the command, prints the result, and then recurs.