CSC241: Homework 4


In this homework 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:

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 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 Homework 3) in your main method that asks for a Room name.