Class Parser

java.lang.Object
  extended by Parser

public class Parser
extends java.lang.Object

This class is used to commands as user input from the keyboard. For full 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 AVAILABLE
          The value that parse() returns if the user enters 'available' to check on the supplies available.
static int BUY
          The value that parse() returns if the user enters 'buy' to buy cargo at the current depot.
static int CHECK
          The value that parse() returns if the user enters 'CHECK' to check on the party's status.
static int DEPOT
          The value that parse() returns if the user enters 'depot' to enter the depot at the current location.
static int DO_NOT_UNDERSTAND
          The value that parse() returns if it did not understand what the user entered.
static int EXIT_DEPOT
          The value that parse() returns if the user enters 'exit' to exit the depot and return to the location.
static int FOOD
          The value that parse() returns if the user enters 'food' to change food rations.
static int HUNT
          The value that parse() returns if the user enters 'hunt' to hunt/forage for food.
static int INVENTORY
          The value that parse() returns if the user enters 'inventory' to display his/her inventory.
static int MOVE
          The value that parse() returns if the user enters 'move' to move to another location on the map.
static int PACE
          The value that parse() returns if the user enters 'pace' to change the pace.
static int QUIT
          The value that parse() returns if the user enters 'quit' to quit the game.
static int REST
          The value that parse() returns if the user enters 'rest' to rest.
static int SELL
          The value that parse() returns if the user enters 'sell' sell items at the depot.
private static java.util.Scanner stdin
          The Scanner object that is used by the various Parser methods
static int TRADE
          The value that parse() returns if the user enters 'TRADE' to trade.
static int WORLDMAP
          The value that parse() returns if the user enters 'worldmap' to print the map.
static int XCHEAT
          The value that parse() returns if the user enters 'xcheat' to enable cheat mode.
 
Constructor Summary
private Parser()
          Making the constructor private prevents anybody from calling it (as we don't want to create objects of this class)
 
Method Summary
static int getInteger()
          This method just reads in an integer, and returns that value.
static int getItemToTrade(Inventory inventory, double priceFactor)
          This method asks the user to enter the number corresponding to the items he/she wants to trade
static int getMoveDirection()
          This method obtains a direction (n/s/e/w) to move, and returns the appropriate constant.
static int parse()
          This method reads in the user's input from the keyboard, and returns a value corresponding to what the user entered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

INVENTORY

public static final int INVENTORY
The value that parse() returns if the user enters 'inventory' to display his/her inventory.

See Also:
Constant Field Values

BUY

public static final int BUY
The value that parse() returns if the user enters 'buy' to buy cargo at the current depot.

See Also:
Constant Field Values

MOVE

public static final int MOVE
The value that parse() returns if the user enters 'move' to move to another location on the map.

See Also:
Constant Field Values

DEPOT

public static final int DEPOT
The value that parse() returns if the user enters 'depot' to enter the depot at the current location.

See Also:
Constant Field Values

EXIT_DEPOT

public static final int EXIT_DEPOT
The value that parse() returns if the user enters 'exit' to exit the depot and return to the location.

See Also:
Constant Field Values

WORLDMAP

public static final int WORLDMAP
The value that parse() returns if the user enters 'worldmap' to print the map.

See Also:
Constant Field Values

SELL

public static final int SELL
The value that parse() returns if the user enters 'sell' sell items at the depot.

See Also:
Constant Field Values

XCHEAT

public static final int XCHEAT
The value that parse() returns if the user enters 'xcheat' to enable cheat mode.

See Also:
Constant Field Values

FOOD

public static final int FOOD
The value that parse() returns if the user enters 'food' to change food rations.

See Also:
Constant Field Values

HUNT

public static final int HUNT
The value that parse() returns if the user enters 'hunt' to hunt/forage for food.

See Also:
Constant Field Values

REST

public static final int REST
The value that parse() returns if the user enters 'rest' to rest.

See Also:
Constant Field Values

PACE

public static final int PACE
The value that parse() returns if the user enters 'pace' to change the pace.

See Also:
Constant Field Values

TRADE

public static final int TRADE
The value that parse() returns if the user enters 'TRADE' to trade.

See Also:
Constant Field Values

CHECK

public static final int CHECK
The value that parse() returns if the user enters 'CHECK' to check on the party's status.

See Also:
Constant Field Values

AVAILABLE

public static final int AVAILABLE
The value that parse() returns if the user enters 'available' to check on the supplies available.

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

stdin

private static java.util.Scanner stdin
The Scanner object that is used by the various Parser methods

Constructor Detail

Parser

private Parser()
Making the constructor private prevents anybody from calling it (as we don't want to create objects of this class)

Method Detail

getItemToTrade

public static int getItemToTrade(Inventory inventory,
                                 double priceFactor)
This method asks the user to enter the number corresponding to the items he/she wants to trade

Parameters:
inventory - the inventory of the current market,
priceFactor - double value indicating the market cost factor
Returns:
an int value indicating the items the user wishes to trade

getInteger

public static int getInteger()
This method just reads in an integer, and returns that value.

Returns:
The integer read in.

getMoveDirection

public static int getMoveDirection()
This method obtains a direction (n/s/e/w) to move, and returns the appropriate constant. The method will loop around until a valid value is entered.

Returns:
A constant in Game (Game.MOVE_NORTH, Game.MOVE_SOUTH, Game.MOVE_EAST, Game.MOVE_WEST) representing the direction to move to.

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, 'tunnel' and 'TIGER' will both return TRADE. The values returned are the fields listed above.

Returns:
An int value indicating what the user entered. These int values are the int constants defined in the Parser class.