Optional Lab - Hunt the Wumpus

The Wumpus

Hunt the Wumpus is a game from a long time ago (1972 -- making it older than Mr. Pavao!) that is brought back in a number of forms as programming lessons. Like this one.

The concept is that you're in a cave, and there's a wumpus (a huge beast that likes to eat people in caves), and you're trying to find gold. In the full version, you've got arrows and there are pits and all sorts of other nifty things. We'll be doing a sort of "Wumpus Lite" for this program, where we're avoiding the wumpus (for now).

In our game, the cave will be a grid that the user clicks on. There are ten coins and one hungry wumpus in the cave. The wumpus and the coins don't move.

If the user clicks on a space that is adjacent to a gold coin, a message appears that they see the glitter of gold nearby. If the user clicks on a space that is adjacent to the wumpus, a message appears that they hear growling.

If the user finds a coin, they pick it up. If the user finds all ten coins, they win and the game ends.

If the user finds the wumpus, they get eaten and the game is over.

First, we'll need a cave. The cave is going to actually be three layers of control arrays. The control arrays will each have 25 members, and be arranged on the form as a 5x5 grid. There will be two arrays of Images and one array of Buttons, all the same vaguely squarish size. The Buttons will start out visible, but the Images will not. You'll also need labels for displaying the current number of coins found and any alert messages.

Within the code, you should track the positions of the coins and the wumpus with one (maybe two) two-dimensional array(s).

Each time the user clicks, the game should take the following steps (note that this is not the full click routine):

  1. If the user found the wumpus, then inform the user, show the wumpus at that space, and end the game.
  2. If the user found a gold coin, inform the user, show the coin at that space, and add a coin to the user's found-coin count.
  3. If the user clicked adjacent to a coin, inform the user "You see the glitter of gold" or something like that.
  4. If the user clicked adjacent to the wumpus, inform the user "You hear growling" or some such.

HINTS: You'll need a start button to start the game and set up the location of the wumpus and the ten coins. Note that the wumpus and coins must be in their own space, so if you get one landing on a space that's already occupied when randomly seeding them, choose another space.

To show a picture, make that object visible and the Button not visible -- don't forget to use the array index!

Don't forget to check to see if you're on a corner or an edge, so you don't inadvertently walk off the edge of your matrix when checking to see if the user clicked adjacent to the coins or wumpus. This might be a good algorithm to use as a Function (a boolean function called IsEdge, maybe?).

Here are the images to use:

wumpus coin

As always, design a useful and proper interface, including tab order and access keys.