Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Assignment 4

In this assignment we primarily deal with user interaction. First you will need to implement the inventory system:

  • Create a class called Inventory which keeps track of the items you have picked up, the total weight of the items, and has a constant for the maximum weight you can carry (25.0). Be sure to follow good practices as far as access modifiers, add a toString, etc.
  • Add methods to add and remove items from the Inventory in the appropriate place. You may want to write a method to ensure you can actually carry an item (the weight is within bounds).

Next, implement some sort of method like the checkRoomConnections method we detailed in class to ensure your rooms are connected properly. I would call this from the endDocument method in your XML handler. If your rooms aren’t connected properly, be sure to fix that before moving on!

Back to user interaction. Implement a public void play(Scanner s) method in the Player class that enters a command loop: it takes a line from the Scanner passed to it, parses the line, executes the command the user entered according to the rules of the game (outputting any relevant information to standard output), and repeats.

You should implement the following commands:

  • help – this command outputs a help message to the user, consisting of the full list of commands that can be used, together with descriptions of what they do (run the example project for a possible help message).
  • look – this command immediately outputs to the user the complete information pertaining to the Room the Player is in (together with all Characters/Items in it, as well as adjacent Doors/Rooms).
  • north, east, south, west – the Player leaves the current Room and enters its respective neighbor. Be careful about special cases (no such neighbor, etc). If the Player cannot execute the command for some reason, provide output to the user accordingly.
  • inspect:[itemname], inspect:[doorname], inspect:[charactername] – print out the result of calling inspectString on the given Inspectable. Make sure the messages look nice and follow rules about when to show hidden items, etc.
  • lock:[doorname], unlock:[doorname] – lock and unlock the given door provided you are carrying the key. Be sure to print good messages if the door is already locked and you try locking it, or if you don’t have the right key, etc.
  • pickup:[itemname], drop:[itemname] – add items to, or remove items from the inventory.
  • exit, quit – these commands print a “Goodbye” message and quit the program.

If the command the user enters is not one of the above, you should output a sensible message (such as “Could not understand, please repeat” or “Stop talking gibberish”) and ask for another one (i.e., start another loop iteration).

This assignment ties up all the loose ends from the previous ones, so it very much depends on their successful completion. You should think about all the special cases as stated in the project description: e.g., what happens if the player inspects in a room with guards, and the guards notice? All of those questions should be answered at this point in your project.

A good way to kick-start the game is to keep track of the Player object in the input file when parsing it (you can be certain there will be a single Player object). Then, after the parsing, call play on that object. You can remove the part (implemented in Assignment 3) in your main method that asks for a Room name.

At the end of this assignment your game should be playable. In the next assignment we will improve some aspects of it and add unit tests to better ensure all of your functionality is working. For now, test by playing the game, keep track of what needs improving, fix it, and play again until you are happy with what you have produced.