antichess
Class GameClock

java.lang.Object
  extended by antichess.GameClock

public class GameClock
extends Object

GameClock is a represents a set of timers for use in a game. GameClock contains a set of GameTimers referenced to by their Player. Only one of these timers are counting down at any one time.

Specification Fields

Constructor Summary
GameClock(Player[] playerList, long[] startTimes)
          playerList is an array of Players which each clock will be associated with startTimes is a list of start times for the players in playerList.
GameClock(Player[] playerList, long[] startTimes, long[] currentTimes)
          playerList is an array of Players which each clock will be associated with startTimes is a list of start times for the players in playerList.
 
Method Summary
 void addListener(GameTimerListener listener, Player player)
           
 Player getCurrentPlayer()
           
 long getTime(Player player)
           
 GameTimer getTimer(Player player)
           
 boolean hasPlayer(Player player)
           
 void setTime(long newTime, Player player)
           
 void startTimer(Player player)
           
 void stopTimer()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameClock

public GameClock(Player[] playerList,
                 long[] startTimes)
playerList is an array of Players which each clock will be associated with startTimes is a list of start times for the players in playerList. Values of the same index correspond to eachother.

Throws:
IllegalArgumentException - if playerList = null, startTimes = null, a value in startTimes is < 0, playerList and startTimes are not the same length
Requires:
playerList must not contain identical elements

GameClock

public GameClock(Player[] playerList,
                 long[] startTimes,
                 long[] currentTimes)
playerList is an array of Players which each clock will be associated with startTimes is a list of start times for the players in playerList. Values of the same index correspond to eachother.

Throws:
IllegalArgumentException - if playerList == null, startTimes == null, currentTimes == null a value in startTimes is < 0, a value in currentTimes is < 0, currentTimes, playerList and startTimes are not the same length
Requires:
playerList must not contain identical elements
Method Detail

addListener

public void addListener(GameTimerListener listener,
                        Player player)
Throws:
IllegalArgumentException - if no timers are referenced by player
Effects:
adds listener to timerListeners mapped to by player
Modifies:
timerListeners

startTimer

public void startTimer(Player player)
Throws:
IllegalArgumentException - if no timers are referenced by player
Effects:
currentTimer = timer mapped to by player
Modifies:
currentTimer

stopTimer

public void stopTimer()
Effects:
sets the currentTimer to none
Modifies:
currentTimer

getTime

public long getTime(Player player)
Returns:
the time remaining on the GameTimer mapped to by player
Throws:
IllegalArgumentException - if no timers are referenced by player

setTime

public void setTime(long newTime,
                    Player player)
Throws:
IllegalArgumentException - if no timers are referenced by player or if newTime < 0
Effects:
sets the Time of the GameTimer mapped to by player to newTime if the GameTimer mapped to by player is not running.
Modifies:
player's Timer

getCurrentPlayer

public Player getCurrentPlayer()
Returns:
currentTimer

getTimer

public GameTimer getTimer(Player player)
Requires:
the GameClock have a timer referenced by player
Returns:
the GameTimer referenced by Player

hasPlayer

public boolean hasPlayer(Player player)
Returns:
true if this GameClock has a timer associated with player