Hi There!

I'm Dan Schlegel, an Associate 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 PC 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 PC is in (together with all Creatures in it).
  • clean – this command changes the state of the current Room accordingly (dirty to half-dirty, half-dirty to clean, clean to clean (does nothing)). Remember that some Creatures may not like the resulting state and act accordingly, potentially altering the respect of the PC.
  • dirty – same as above, only the change is in the opposite direction.
  • north, east, south, west – the PC leaves the current Room and enters its respective neighbor. Be careful about special cases (no such neighbor, room full, etc). If the PC cannot execute the command for some reason, provide according output to the user.
  • 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: what happens if some Creature does not like the state of the Room it is in, but the Room has no neighbors or all of them are full? What happens if a Creature leaves its Room only to find that it does not like the next one? 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 PC object in the input file when parsing it (you can be certain there will be a single PC 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.