` Program Four

Program One

The Wumpus

One of the first computer games in the 1970's was an adventure game called "Hunt the Wumpus". In this game, you are forced to wander around a maze of caves, hunting the dreaded wumpus (or possible more than one wumpi). When you enter a cave that is adjacent to a wumpus, you will smell its stench. Warned by your nose, you can then throw a hand grenade into an adjacent cave to try to kill the wumpus. Unfortunately, the sound of the explosion will alert any nearby wumpi and set them in motion. The object of the game is to kill all of the wumpi before you run out of grenades (and without getting killed). In addition to wumpi, there is a bottomless pit and giant bats to avoid. Below is a sample execution of the game.

HUNT THE WUMPUS:  Your mission is to explore the maze of caves 
and destroy all of the wumpi (without getting yourself killed).
To move to an adjacent cave, enter 'M' and the tunnel number.
To toss a grenade into a cave, enter 'T' and the tunnel number.

You are currently in The Fountainhead
    (1) unknown
    (2) unknown
    (3) unknown

What do you want to do? m 2

You are currently in The Silver Mirror
    (1) The Fountainhead
    (2) unknown
    (3) unknown

What do you want to do? m 3

You are currently in Shelob's Lair
    (1) The Silver Mirror
    (2) unknown
    (3) unknown
You smell an awful stench coming from somewhere nearby.

What do you want to do? t 2

Missed, dagnabit!
A startled wumpus charges into your cave... CHOMP CHOMP CHOMP
GAME OVER

You have been given the following classes to represent the maze structure and implement the text-based game:

Part 1: Cave

You are to implement the Cave class, which models a single cave in the maze. Each cave has a name and a number associated with it, and is connected to three other caves through tunnels. By default, a cave is empty (using the enumerated type value CaveContents.EMPTY) but it can be assigned to contain a wumpus (CaveContents.WUMPUS), a swarm of bats (CaveContents.BATS), or a bottomless pit (CaveContents.PIT). In addition, a cave is initially unvisited, but it can be marked as visited.

Be sure to test your Cave class thoroughly.

Part 2: CaveMaze

An incomplete implementation of the CaveMaze class is provided. Currently, it reads in the cave data file (caves.txt) and allows the player to move around the maze. You are to complete the functionality of the game by making the following additions.

  1. The constructor should place a swarm of bats, a bottomless pit, and between 1 and 4 wumpi in random caves (excluding the starting cave with number 0). The number of wumpi should be randomly chosen for each game so that the player is never sure exactly how many there will be. The player should also be given 3 grenades for each wumpus.
  2. To avoid excessive duplication of code, you must 
    1. define a private helper method that finds a random empty cave in the maze (by repeatedly picking a random index until the index of an empty cave is picked).
    2. define a private helper method that finds a random empty non-zero cave in the maze.
    3. The CaveMaze class may NOT contain any System.out.println statements.
  3. Modify the showLocation method so that a warning is given if the player is adjacent to a cave containing a wumpus ("You smell an awful stench coming from somewhere nearby."), the bottomless pit ("You feel a draft coming from one of the tunnels."), or bats ("You hear the flapping of wings close by."). Note that it is possible that more than one message might be displayed depending on the contents of the adjacent caves.
  4. Modify the move method so that moving into a nonempty cave has consequences. If the cave contains a wumpus or the bottomless pit, the player is killed (with an appropriate message returned). If the cave contains the bats, then the player is picked up and dropped off in a random empty cave in the maze (with an appropriate message returned).
  5. Modify the toss method so that it tosses a grenade (assuming the player has any remaining) into the specified tunnel. If that tunnel contains a wumpus, then it is killed. However, any wumpi adjacent to the player are alerted by the sound of the explosion and move at random. That is, each adjacent (surviving) wumpus picks a tunnel at random. If the cave along that tunnel is empty, then the wumpus moves there. If that happens to be the cave where the player is, then he/she is killed.

Submission

Upload the result to blueline. You should upload a single compressed file for this assignment that contains the complete project (not just src files).