Hi There!

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

Assignment 4

In this assignment we deal with 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. We will not yet have the timer implemented – we’ll save that for the next assignment.

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).
  • 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 according output to the user.
  • shake:[itemname], possess:[itemname], throw:[itemname] – these commands allow manipulating the objects in the room, causing a reaction from the other Characters. Allow the user to type the actual item name, e.g., shake:white lamp.
  • 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 homework 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 some Character enters a room with broken items? 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.