es.ucm.fdi.hysteria.console
Class Parser

java.lang.Object
  extended by es.ucm.fdi.hysteria.console.Parser
All Implemented Interfaces:
java.io.Serializable

public class Parser
extends java.lang.Object
implements java.io.Serializable

Represents the parser of the game engine that analyzes the input stream and identifies valid commands.

Author:
Sandor
See Also:
Serialized Form

Field Summary
protected  java.util.Vector<Command> _commandPrototypes
          Contains the prototypes of every command that the player can use during the game
protected  GameConfig _config
          Config
protected  Engine _engine
          Engine
protected  Game _game
          A reference to the game that created the Interpreter
protected  java.util.Scanner _reader
          Scanner needed for reading from keyboard
static java.lang.String LINE_SEPARATOR
          Platform-independent line separator
 
Constructor Summary
Parser(java.io.InputStream in, Game theGame, Engine theEngine)
          Constructs a parser, specifying the input stream from which the game receives the player commands and a reference to the game itself (to be used for constructing the commands), assuming the default configuration.
Parser(java.io.InputStream in, Game theGame, Engine theEngine, java.util.Properties config)
          Constructs a parser, specifying the input stream from which the game receives the player commands, a reference to the game itself (to be used for constructing the commands) and a new configuration.
 
Method Summary
 boolean hasNextCommand()
          Checks whether there is text for another command in the player input.
 Command parseNextCommand()
          Parses the player input, consuming its characters and returning the next command that has been identified.
 java.lang.String reportHelp()
          Reports the help information of all the available commands.
 void setConfig(java.util.Properties config)
          Sets a new configuration.
 void setGame(Game theGame)
           
 void setInput(java.io.InputStream input)
          Sets the input stream for the parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_reader

protected java.util.Scanner _reader
Scanner needed for reading from keyboard


_commandPrototypes

protected java.util.Vector<Command> _commandPrototypes
Contains the prototypes of every command that the player can use during the game


_game

protected Game _game
A reference to the game that created the Interpreter


_config

protected GameConfig _config
Config


_engine

protected Engine _engine
Engine


LINE_SEPARATOR

public static java.lang.String LINE_SEPARATOR
Platform-independent line separator

Constructor Detail

Parser

public Parser(java.io.InputStream in,
              Game theGame,
              Engine theEngine)
       throws java.lang.IllegalArgumentException
Constructs a parser, specifying the input stream from which the game receives the player commands and a reference to the game itself (to be used for constructing the commands), assuming the default configuration.

Parameters:
in - Input stream
theGame - The Game
Throws:
java.lang.IllegalArgumentException - Arguments in, theGame cannot be null

Parser

public Parser(java.io.InputStream in,
              Game theGame,
              Engine theEngine,
              java.util.Properties config)
       throws java.lang.IllegalArgumentException
Constructs a parser, specifying the input stream from which the game receives the player commands, a reference to the game itself (to be used for constructing the commands) and a new configuration.

Parameters:
in - Input stream
theGame - The Game
config - The config
Throws:
java.lang.IllegalArgumentException - Arguments in, theGame and config cannot be null
Method Detail

hasNextCommand

public boolean hasNextCommand()
Checks whether there is text for another command in the player input.

Returns:
true if there is text for another command; false otherwise.

parseNextCommand

public Command parseNextCommand()
                         throws NoNextCommandException
Parses the player input, consuming its characters and returning the next command that has been identified.

Returns:
The parsed command. It can be null, meaning an invalid command was parsed.
Throws:
NoNextCommandException - There is no next command to parse.

reportHelp

public java.lang.String reportHelp()
Reports the help information of all the available commands.

Returns:
The help information.

setConfig

public void setConfig(java.util.Properties config)
               throws java.lang.IllegalArgumentException
Sets a new configuration. Properties that are not overriden maintain their previous values.

Parameters:
config - The config
Throws:
java.lang.IllegalArgumentException - Argument config cannot be null

setInput

public void setInput(java.io.InputStream input)
              throws java.lang.IllegalArgumentException
Sets the input stream for the parser.

Parameters:
input - The input
Throws:
java.lang.IllegalArgumentException - Argument "input" cannot be null

setGame

public void setGame(Game theGame)
             throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException