org.dartra.standard
Class StandardGame

java.lang.Object
  extended byorg.dartra.standard.PersistentObject
      extended byorg.dartra.standard.StandardGame
All Implemented Interfaces:
Game, Persistent
Direct Known Subclasses:
AroundTheClockGame, BaseballGame, CricketGame, GolfGame, StandardMatch, TargetPracticeGame, X01Game

public abstract class StandardGame
extends PersistentObject
implements Game

Standard base implementation of the Game interface.

Author:
Erwin Vervaet

Constructor Summary
StandardGame(java.lang.String name, Board board)
           
StandardGame(java.lang.String name, Board board, Player[] players)
           
 
Method Summary
 void accept(GameVisitor visitor)
          Have given visitor process the data in this game.
 void addGameEventListener(GameEventListener gel)
          Add given game event listener to the list of listeners that will be notified when a game event occurs.
protected  void addTurn(Turn t)
          Add a turn to the game.
 Board getBoard()
          Returns the board the game is played on.
 Player getCurrentPlayer()
          Return the currently active player.
 Turn getCurrentTurn()
          Returns the currently active turn of the game.
 long getEndTime()
          Returns the time at which the game ended, or -1 if it did not yet end.
 Player getFirstPlayer()
          Returns the player that will be the first to throw.
 java.util.Vector getGameEventListeners()
          Get the collection of game event listeners maintained by this object.
 java.lang.String getName()
          Return the name of this game.
 Player getPlayer(int index)
          Get a particular player participating in the game.
 java.util.Vector getPlayers()
          Returns the list of players participating in the game.
 Turn getPlayerTurn(Player player, int index)
          Get the specified turn for given player.
 java.util.Vector getPlayerTurnHistory(Player player)
          Returns a list representing the turn history of given player in this game.
abstract  StringProperties getProperties()
          Subclasses should implement this to properly return their game specific properties (for instance the "start score" for an x01 game).
 long getStartTime()
          Returns the time at which the game started, or -1 if it did not yet start.
 Turn getTurn(int index)
          Get specified turn of the game.
 java.util.Vector getTurnHistory()
          Returns a list containing all turns of the game so far.
 Player getWinner()
          Returns the player that won the game, or null if no winner has been established yet.
 void removeGameEventListener(GameEventListener gel)
          Remove given game event listener from the list of listeners maintained by this object.
protected  void setEndTime(long ts)
           
 void setFirstPlayer(Player player)
          Set the player that will be the first to throw.
protected  void setPlayers(Player[] players)
          Set the players of the game.
protected  void setStartTime(long ts)
           
 void setWinner(Player player)
          Set the winner of the game.
 void start()
          Start the game.
 java.lang.String toString()
           
 boolean undoHit()
          Undo the effect of the last hit.
 
Methods inherited from class org.dartra.standard.PersistentObject
getId, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.dartra.framework.Game
getObjective, getPlayerScore, registerHit
 
Methods inherited from interface org.dartra.framework.Persistent
getId, setId
 

Constructor Detail

StandardGame

public StandardGame(java.lang.String name,
                    Board board)

StandardGame

public StandardGame(java.lang.String name,
                    Board board,
                    Player[] players)
Method Detail

getBoard

public Board getBoard()
Description copied from interface: Game

Returns the board the game is played on.

Specified by:
getBoard in interface Game

setPlayers

protected void setPlayers(Player[] players)

Set the players of the game. Use this method if you did not pass the players to the constructor.

Players must be set before starting the game and can only be set once.


getPlayers

public java.util.Vector getPlayers()
Description copied from interface: Game

Returns the list of players participating in the game. The returned list contains Player objects.

Specified by:
getPlayers in interface Game

getPlayer

public Player getPlayer(int index)
Description copied from interface: Game

Get a particular player participating in the game.

Specified by:
getPlayer in interface Game

setFirstPlayer

public void setFirstPlayer(Player player)
Description copied from interface: Game

Set the player that will be the first to throw.

Specified by:
setFirstPlayer in interface Game

getFirstPlayer

public Player getFirstPlayer()
Description copied from interface: Game

Returns the player that will be the first to throw.

Specified by:
getFirstPlayer in interface Game

setWinner

public void setWinner(Player player)

Set the winner of the game. A standard game ends when the winner is set.

Specified by:
setWinner in interface Game

getWinner

public Player getWinner()
Description copied from interface: Game

Returns the player that won the game, or null if no winner has been established yet.

Specified by:
getWinner in interface Game

setStartTime

protected void setStartTime(long ts)

getStartTime

public long getStartTime()
Description copied from interface: Game

Returns the time at which the game started, or -1 if it did not yet start.

Specified by:
getStartTime in interface Game

setEndTime

protected void setEndTime(long ts)

getEndTime

public long getEndTime()
Description copied from interface: Game

Returns the time at which the game ended, or -1 if it did not yet end.

Specified by:
getEndTime in interface Game

getName

public java.lang.String getName()
Description copied from interface: Game

Return the name of this game.

Specified by:
getName in interface Game

start

public void start()

Start the game. For a standard game this means that a new turn is created for the current player (normally the first player, as indicated by the getFirstPlayer() method).

Specified by:
start in interface Game

undoHit

public boolean undoHit()

Undo the effect of the last hit. For a standard game, this means that the last throw of the last turn is removed. If the last turn does not yet contain a throw, the turn history is rolled back to the previous turn, and the last throw of that turn is removed.

Specified by:
undoHit in interface Game

getCurrentPlayer

public Player getCurrentPlayer()

Return the currently active player. For a standard game this is the player of the current turn, or if no turn has been started yet, the first player of the game, as returned by the getFirstPlayer() method.

Specified by:
getCurrentPlayer in interface Game

getCurrentTurn

public Turn getCurrentTurn()

Returns the currently active turn of the game. For a standard game this is the last (most recent) turn.

Specified by:
getCurrentTurn in interface Game

getPlayerTurn

public Turn getPlayerTurn(Player player,
                          int index)
Description copied from interface: Game

Get the specified turn for given player.

Specified by:
getPlayerTurn in interface Game

getPlayerTurnHistory

public java.util.Vector getPlayerTurnHistory(Player player)
Description copied from interface: Game

Returns a list representing the turn history of given player in this game. The first element in the list is the first turn, the last element the most recent turn.

The returned list contains Turn objects.

Specified by:
getPlayerTurnHistory in interface Game

addTurn

protected void addTurn(Turn t)

Add a turn to the game.


getTurn

public Turn getTurn(int index)
Description copied from interface: Game

Get specified turn of the game.

Specified by:
getTurn in interface Game

getTurnHistory

public java.util.Vector getTurnHistory()
Description copied from interface: Game

Returns a list containing all turns of the game so far. The first element in the list is the first turn, the last element the most recent turn.

The returned list contains Turn objects.

Specified by:
getTurnHistory in interface Game

addGameEventListener

public void addGameEventListener(GameEventListener gel)
Description copied from interface: Game

Add given game event listener to the list of listeners that will be notified when a game event occurs.

Specified by:
addGameEventListener in interface Game

removeGameEventListener

public void removeGameEventListener(GameEventListener gel)
Description copied from interface: Game

Remove given game event listener from the list of listeners maintained by this object.

Specified by:
removeGameEventListener in interface Game

getGameEventListeners

public java.util.Vector getGameEventListeners()
Description copied from interface: Game

Get the collection of game event listeners maintained by this object. The returned collection contains GameEventListener objectgs.

Specified by:
getGameEventListeners in interface Game

accept

public void accept(GameVisitor visitor)
Description copied from interface: Game

Have given visitor process the data in this game.

Specified by:
accept in interface Game

getProperties

public abstract StringProperties getProperties()

Subclasses should implement this to properly return their game specific properties (for instance the "start score" for an x01 game).

It is legal to return null if there are no game specific properties.


toString

public java.lang.String toString()