Exercise: Another Game, Maze
After learning so many new, strange concepts—references and structures—you deserve a little diversion. This exercise demonstrates a structure and a few references and allows you to play a simple game.
In the manner of classic games such as Adventure, Zork, or Hunt the Wumpus, you will be placed in a maze and need to find your way around. The maze is featureless, consisting of only rooms with at least one doorway. The doorways lead to adjacent rooms to the north, south, east, or west. The object is to find the secret room. You'll find only a couple of paths to take to that room and many dead-end paths.
To get started, type Listing 13.2 and save it as Maze. Running the program gives output similar to Listing 13.1.
Get Sams Teach Yourself Perl in 24 Hours now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.