<#48347#>Figure: A tour of a university<#48347#>
<#48380#>Figure: Take the tour<#48380#>
Early computer games asked players to find their way through dangerous
mazes and caves. The player wanders from cave to cave, finds treasures,
encounters creatures of all kinds, fights, kisses, picks up energy, and
eventually reaches paradise. This section lays out the basics of such a
game, using our iterative approach to program design.
Our tour takes place at one of the scariest places of all: campus. A campus
consists of buildings, one more dangerous than the other. Each building has
a name and is connected to a bunch of other buildings.
The player is always in a building. We refer to this building as the <#48349#>current location<#48349#>. To find out more about the location, the player can
ask for a picture of the building and for the list of connections. The
player can also move to one of the connected buildings by issuing a
<#68824#><#48350#>go<#48350#><#68824#> command.
<#48353#>Exercise 37.5.1<#48353#>
If the player issues the command <#68829#><#48370#>(go<#48370#>\ <#48371#>s)<#48371#><#68829#> and <#68830#><#48372#>s<#48372#><#68830#> is not
connected to the current location, the function must report an error.
Develop other functions as necessary or as
desired.~ Solution<#68831#><#68831#>
~
Players of early maze games could also gather objects and trade objects at
the various sites. Specifically, the player had a bag for carrying objects,
and each site contained objects that the player could trade for things in
the bag.
<#48384#>Exercise 37.5.3<#48384#>
The three exercises in this section illustrate how maze games work. From
here it is easy to experiment with various flavors of the game. Taking a
walk from one building to another may take some energy, and the player may
have only a finite amount of energy. Creatures may fight or kiss the
player, which consumes or replenishes the player's energy level. Use your
imagination to extend the game and have friends take the tour.