Class Parser

java.lang.Object
  extended by Parser

public class Parser
extends java.lang.Object

This class is used to get user input from the keyboard. For full details of the Parser class, see Lab 9. This class does not have a constructor, and all it's methods are static. Thus, they are called by Parser.parse(), for example.


Field Summary
static int ATTACK
          The value that parse() returns if the user enters 'attack' to attack the creature in the room.
static int DO_NOT_UNDERSTAND
          The value that parse() returns if it did not understand what the user entered.
static int EAST
          The value that parse() returns if the user enters 'east' to move to the room to the east.
static int GET
          The value that parse() returns if the user enters 'get' to pick up the weapon in the room.
static int LOOK
          The value that parse() returns if the user enters 'look' to see the room description again.
static int NORTH
          The value that parse() returns if the user enters 'north' to move to the room to the north.
static int QUIT
          The value that parse() returns if the user enters 'quit' to quit the game.
static int SOUTH
          The value that parse() returns if the user enters 'south' to move to the room to the south.
static int WEST
          The value that parse() returns if the user enters 'west' to move to the room to the west.
 
Method Summary
static boolean askYesNoQuestion(java.lang.String prompt)
          This method asks the question passed as a parameter, and keeps asking it until a yes or no answer is obtained.
static int parse()
          This method reads in the user's input from the keyboard, and returns a value corresponding to what the user entered.
static void printCommands()
          This method prints the available command to the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
The value that parse() returns if the user enters 'north' to move to the room to the north.

See Also:
Constant Field Values

EAST

public static final int EAST
The value that parse() returns if the user enters 'east' to move to the room to the east.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
The value that parse() returns if the user enters 'south' to move to the room to the south.

See Also:
Constant Field Values

WEST

public static final int WEST
The value that parse() returns if the user enters 'west' to move to the room to the west.

See Also:
Constant Field Values

ATTACK

public static final int ATTACK
The value that parse() returns if the user enters 'attack' to attack the creature in the room.

See Also:
Constant Field Values

LOOK

public static final int LOOK
The value that parse() returns if the user enters 'look' to see the room description again.

See Also:
Constant Field Values

GET

public static final int GET
The value that parse() returns if the user enters 'get' to pick up the weapon in the room.

See Also:
Constant Field Values

QUIT

public static final int QUIT
The value that parse() returns if the user enters 'quit' to quit the game.

See Also:
Constant Field Values

DO_NOT_UNDERSTAND

public static final int DO_NOT_UNDERSTAND
The value that parse() returns if it did not understand what the user entered.

See Also:
Constant Field Values
Method Detail

printCommands

public static void printCommands()
This method prints the available command to the screen. The commands correspond to the field values shown above.


parse

public static int parse()
This method reads in the user's input from the keyboard, and returns a value corresponding to what the user entered. The method only really looks at the first character entered, and ignores case. Thus, 'aardvark' and 'APPLE' will both return ATTACK. The values returned are the fields listed above.

Returns:
An int value indicating what the user entered.

askYesNoQuestion

public static boolean askYesNoQuestion(java.lang.String prompt)
This method asks the question passed as a parameter, and keeps asking it until a yes or no answer is obtained.

Parameters:
prompt - The question to ask.
Returns:
true if the user entered yes, false if the user entered no