Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Vertex class represents a cave room, or a grid cell of the graph.  It can be connected to other vertices through cardinal directions(north, east, south, west) and stores information regarding its neighbors, position, cost, and whether it is marked (this is for shortesPath() method), and visibility information.  I saved the neighbors in java's built-in hashmap so that it would be easier to identify a neighbor with particular direction.  Hashmap's (key, value) feature was handy in Vertex's draw() method.

(Snippet 1.)


Graph class maintains a list of vertices, in my case as an arrayList, and establishes links between the vertices.  It is essentially a map of the game; however, it is different from landscape because it does not involve any drawing of the agent classes.  When compiling and running my please provide one command line argument: 0 to implement java's built-in priority queue or 1 to implement my own PQHeap.  I will explain my implementation of PQHeap in the extension section.

Based on shortestPath() and draw() method of vertex, grid cells that are two distances away from wumpus will be colored red.  The rest will be colored gray.  The corridors to the nearby grid cells are colored yellow.  See below Figure 1. for an illustration.

 (Figure 1.)

Note that green square is the wumpus, and pink circle is the hunter.  I manually set the visibility of wumpus and all vertices to true just for an illustration.


Similar to Hunter class, Wumpus class stores information regarding its location and visibility status.  In addition, it contains a field about how to pose depending on the result of the game.  In case of hunter's defeat, it will appear on the window and be colored green like in the above illustration.  If hunter succeeds in killing wumpus, wumpus will disappear and be colored red.  See below illustrationFigure 2.

 (Figure 2.)


Landscape class is slightly modified from that of project 5; its main functionality is still to draw all the agent classes in it.  In addition, it now adds foreground agents - Hunter and Wumpus - and background agents - Vertex - to two separate LinkedLists and stores the lists separately.  The reason is that vertices need to be drawn first, and then hunter and wumpus if applicable.  Therefore, Landscape class's draw() method draws background agents first.

 (Snippet 2.)


HuntTheWumpus is a lengthy class because it contains java swing's GUI and user interface elements in addition to landscape, graph, 2D array for graph, hunter, wumpus, and other necessary instance variables.  Note that I did not create a separate LandscapeDisplay class; everything happens in HuntTheWumpus class.


My user interface elements are essentially controlled by the texts of JLabels that I created such as status(whether hunter's arrow is armed) and outcome(whether hunter won or lost).  For example, key w will move the hunter to north as long as hunter is unarmed and not lost.  See below snippet for detail.

 (Snippet 3.)

In order to run HuntTheWumpus class, user must provide three command line arguments: 1) number of rows/columns to create, 2) which implementation to use for shortesPath() method: 0 for java's built-int priority queue or 1 for my own PQHeap implementation, and 3) number of rows given to the hunter.  If user types 7, 0, 3 as arguments, the program will create 7x7 grid of vertices and give three arrows to the hunter.  More details about the arguments are provided in the extensions section.

 (Figure 3.)


  • Use your own priority queue (heap) implementation. For real extension credit, do something that compares your PQ with the built-in one.


I added three JLabels.  From the right, 1st label indicates the number of left arrows to shoot; 2nd shows the armed status of hunter, either Unarmed or Knock!!!; 3rd shows the output of the game, either TBD, LOST, or WIN.  Lastly, I added quit and reset button.  Reset button locates hunter and wumpus to new random locations.  In addition, it restores initial status of JLabels and calculates the distances of vertices again using shortesPath() method.

 (Snippet 4.)


  • Make the game visually interesting.

I colored vertices, hunter, wumpus, corridors, and background all differently.
 (Figure 4.)
  • Modify the rules so the game is more challenging. Add traps, transporters, or additional levels. Think carefully about balancing the gameplay.

In order to make the game more challenging, I added an additional element, number of arrows.  Throughout the game, hunter can only have limited number of arrows to shoot.  I incorporated this by adding a new integer instance variable count and used it to control keyListener actions.

 (Snippet 5.)

Once the number of possible arrows becomes 0, hunter loses.  I found that it is challenging to play HuntTheWumpus when the number of rows/columns is 5 or smaller, and the number of possible arrows is 3 or smaller.  Below is the demo of playing the game.