COMP 131

Lab #11 - Zuul

Reading:

Chapter 7 of the text.

The Assignment:

First, create a Lab11 folder in your COMP131 folder, and download and unpack the zuul project into this folder. Do NOT use the zuul-bad or zuul-better projects from the textbook.

Part I: (Maximum score 70%)

Modify the zuul project as follows:

  1. Create a test class for the Room class that fully tests the class.
  2. In some games it might be desirable to allow rooms to have exits with arbitrary names (e.g. "window", "stairway") To support such exits it would be better to store the exits in a HashMap with the name of the exit as the key and the Room outside that exit as the value. Refactor the Room class to store the exits in a HashMap.
  3. Re-run the tests that you created in the previous to ensure that the Room class still functions as expected. Also extend your tests for the Room class to include a new exit with an arbitrary name.
  4. Play the game to check that it still works.
  5. Currently the Game class generates and displays the list of exits for each room that the player visits. This does not seem to be a very cohesive design. The exits of a room are something associated with the Room class. Thus, it should be the responsibility of the Room class to generate a list of its own exits. Add a getExitString method to the Room that returns a String listing the exits from the room. For example, if the room has exits to the north and west, this method should return a String of the form: "Exits: north west". Be sure to add tests for this new functionality of the Room class. Hint: the keySet method of the HashMap class will be useful here.
  6. Now that each Room is capable of generating a list of its own exits. Refactor the printLocationInfo method of the Game class to take advantage of this functionality. (Call the getExitString method that you added in the previous exercise.)
  7. Add the getLongDescription method to the Room class as described on page 206 of the text and refactor the Game class to use it whenever the Game needs to print information about a Room.
  8. The constructor for the Game class has poor cohesion - it creates the rooms and adds the valid command words. Make the constructor more cohesive by factoring the code for adding the command words out into its own method and then calling that method from the constructor.
  9. Do Exercises 7.53 and 7.54 in the text. You should NOT write test cases for your main method. Web-CAT will make a small point deduction for not having statement coverage for main, but your instructor will return those points when grading.
Additionally, every method must contain a descriptive javadoc comment. Each parameter must be documented using the @param tag, and any return value must be described using the @return tag. Also, be sure to update the javadoc comments for any methods that you modify so that they accurately reflect the purpose of the method.

Part II: (Maximum Score 85%)

  1. Design your own text-based adventure game, using the world-of-zuul game as a starting point. Some possible game scenarios are described in Exercise 7.3 of the text - you may use one of these or choose your own. Your game can be set on a college campus if you wish, but the rooms must be different from those currently found in the zuul game. If you need additional inspiration, try playing the original Colossal Cave Adventure game.

    Some additional specifications:

    If you find it difficult to visualize this sort of game scenario, try modeling your game on some familiar real-world location.

    Write a brief description of your game, including the setting for the game, the items in the game, and how a player wins. Additionally, draw a map for your game scenario. Label the rooms and the exits (connections between rooms), and specify the locations of the items. The map can be hand-drawn - you do not need to use a drawing program.

  2. Update the comments at the beginning of the Game class and the message displayed by the printWelcome method so that they describe your game.
  3. Change the createRoomsAndPlayer method in the Game class so that it creates the rooms and exits that you invented for your game. You do not need to add any items to your game yet. You will add items in a later exercise.
  4. Update the test methods in the GameTest class as necessary to account for your changes to the Game class. You can directly edit the code in these classes, or delete any test methods that do not pass and re-record them. Do NOT write a test method for the play method of the Game class (Web-CAT can not read input from your keyboard so it will wait forever)! Web-CAT will make a small point deduction for not having statement coverage for this method, but your instructor will return these points when grading.

Part III: (Maximum Score 100%)

  1. Create an Item class to represent items in your game. Items must have at least a name and a description. However, items may also have any other attributes that make sense for your game (e.g. weight, color). Additionally, add a test class for your Item class, and record test cases as needed to achieve statement coverage.
  2. Allow each room in your game to contain one item. When the player enters a room, the name and description of the item (if there is one) in the room should be displayed along with the exits (but note that the room may or may not contain an item). Also, edit the Game class to create and add the items for your game to the appropriate rooms, as specified by your map. Recall that your game must include at least four items. Include test methods for any methods that you add or modify.
  3. Add support to the game that allows the player to pickup and carry any number of items. You should modify the game so that it recognizes the command take which picks up the item in the current room if there is one. If there is no item the take command should print an error message. Be sure to include test methods for any methods that you add or modify.
  4. Add support to the game for an inventory command that prints a list of the items that the player is currently carrying. Keep the concept of cohesion in mind as you decide how to add support for this command.
  5. Add support to the game for a drop command so that the player can drop an item by name (e.g. "drop book"). The dropped item should appear in the current room. If the current room already contains an item, the drop command should print an error message indicating that the room is full and the player should continue to carry the item.
  6. Notice that when you use the help command take, inventory and drop do not appear as command words. Modify the printHelp method of the Game class so that it automatically displays any new command words that are added to the game. Hint: there is a helpful method in the CommandReader class.

Bonus Problems:

Complete any or all of the following exercises for extra credit. You must explicitly state which (if any) of these bonus problems you have done in your written game description.

  1. Problems worth at most 2 extra credit points:
    1. Exercise 7.42 in the text.
    2. Exercise 7.43 in the text.
  2. Problems worth at most 4 extra credit points:
    1. Exercise 7.23 in the text.
    2. Exercise 7.44 in the text.
    3. Exercise 7.45 in the text.
    4. Exercise 7.46 in the text.
    5. Allow each room to contain a collection of items (rather than just one).
    6. Add a look command that allows the player to to look at an item in the current room by name. For example, if the player types look book and there is an item named "book" in the current room, your game should display the description of that item. If there is no such item, your game should display an error message. If the player enters the look command with no second word, it should display the long description of the room.
  3. Problems worth at most 6 extra credit points:
    1. Exercise 7.26 in the text.
    2. Exercise 7.48 in the text.
    3. Modify your game to allow the player to win (as you described in your game scenario).
  4. Problems worth at most 8 extra credit points:
    1. Do Exercise 7.49 in the text. Note that you must do Exercise 7.48 before doing this one. Hints:
      • You can add the following method to the Room class to randomly choose an exit for the character when it moves. Note that exits is the field (of type HashMap) that contains the exits for the room - if you used a different field name, use that name instead.
            /**
             * choose a potential exit at random
             */
            public String randomExit() {
                Object [] dirs = exits.keySet().toArray();
                int index = (int) (Math.random() * dirs.length);
                return (String) dirs[index];
            }
        
      • Your test cases for character movement do not need to check the location of the character after moving (because characters may move randomly).
  5. Variable credit: if some other game modification or extension makes more sense for your game scenario, you may make this modification or extension for extra credit with approval of your instructor. You must also thoroughly describe this modification or extension in your written game description.

Submitting Your Solution:

You must submit your zuul project via Web-CAT. The written description of your game and map should be handed in at the final class meeting. Include a list of the bonus problems that you completed (if any) with your game description.