org.dartra.framework
Interface Game

All Superinterfaces:
Persistent
All Known Subinterfaces:
Match
All Known Implementing Classes:
ScramCricketGame, StandardGame, StandardMatch, X01Match

public interface Game
extends Persistent

A game of darts. A number of players play a game of darts on a particular board. Those players will have their game property set appropriately.

Game objects create the internal game related objects used to manage their state. As such, a Game object is a factory for GameEvent, Objective, Score, Turn and Throw objects.

A game object exposes the following protocol:

 Game game=new SomeGame(...);
 game.start();
 while (game.getWinner()==null) {
     Objective o=game.getObjective();
 
     //do whatever is needed to get the user to obtain the objective
     Zone targetZone=...;
     Hit hit=...;
 
     game.registerHit(targetZone, hit);
 }
 

Game objects have reference semantics. Each Game object represents a unique darts game.

Author:
Erwin Vervaet

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.
 Board getBoard()
          Returns the board the game is played on.
 Player getCurrentPlayer()
          Returns the current player of the game, the player that is currently on throw.
 Turn getCurrentTurn()
          Return 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.
 Objective getObjective()
          Get the current objective of the game: the current player should try to hit a zone of the board, or should end this turn.
 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.
 Score getPlayerScore(Player player)
          Get the current score for given player in this 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.
 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 registerHit(Zone targetZone, Hit hit)
          Register the hit of a dart on the board.
 void removeGameEventListener(GameEventListener gel)
          Remove given game event listener from the list of listeners maintained by this object.
 void setFirstPlayer(Player player)
          Set the player that will be the first to throw.
 void setWinner(Player winner)
          Set the player that won the game.
 void start()
          Start the game.
 boolean undoHit()
          Undo the effect of the last hit that was registered via registerHit() method.
 
Methods inherited from interface org.dartra.framework.Persistent
getId, setId
 

Method Detail

getName

public java.lang.String getName()

Return the name of this game.


getBoard

public Board getBoard()

Returns the board the game is played on.


getPlayers

public java.util.Vector getPlayers()

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


getPlayer

public Player getPlayer(int index)

Get a particular player participating in the game.


setFirstPlayer

public void setFirstPlayer(Player player)

Set the player that will be the first to throw.


getFirstPlayer

public Player getFirstPlayer()

Returns the player that will be the first to throw.


setWinner

public void setWinner(Player winner)

Set the player that won the game.


getWinner

public Player getWinner()

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


getStartTime

public long getStartTime()

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


getEndTime

public long getEndTime()

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


start

public void start()

Start the game.


getObjective

public Objective getObjective()

Get the current objective of the game: the current player should try to hit a zone of the board, or should end this turn.


registerHit

public void registerHit(Zone targetZone,
                        Hit hit)

Register the hit of a dart on the board. A particular zone of the board was targetted.


undoHit

public boolean undoHit()

Undo the effect of the last hit that was registered via registerHit() method. Returns whether or not the undo was successfull.


getPlayerScore

public Score getPlayerScore(Player player)

Get the current score for given player in this game.


getCurrentPlayer

public Player getCurrentPlayer()

Returns the current player of the game, the player that is currently on throw.


getCurrentTurn

public Turn getCurrentTurn()

Return the currently active turn of the game.


getPlayerTurn

public Turn getPlayerTurn(Player player,
                          int index)

Get the specified turn for given player.


getPlayerTurnHistory

public java.util.Vector getPlayerTurnHistory(Player player)

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.


getTurn

public Turn getTurn(int index)

Get specified turn of the game.


getTurnHistory

public java.util.Vector getTurnHistory()

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.


addGameEventListener

public void addGameEventListener(GameEventListener gel)

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


removeGameEventListener

public void removeGameEventListener(GameEventListener gel)

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


getGameEventListeners

public java.util.Vector getGameEventListeners()

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


accept

public void accept(GameVisitor visitor)

Have given visitor process the data in this game.