heurgame.event
Class TurnDispatcher

java.lang.Object
  extended byheurgame.event.TurnDispatcher
All Implemented Interfaces:
LogWriter

public class TurnDispatcher
extends java.lang.Object
implements LogWriter

Author:
David Kaplin Creates the Turn Events and registers the Turn Listeners It also notifies them when a turn starts and ends.

Field Summary
protected  int currentTurn
           
protected  java.util.Vector mylisteners
           
protected  java.util.Vector normalLog
           
protected  int totalTurns
           
protected  int turnsInRound
           
protected  java.util.Vector urgentLog
           
 
Constructor Summary
TurnDispatcher(int total, int current, int turnsRound)
          Creates a new TurnDispatcher.
 
Method Summary
 void addTurnListener(TurnListener t)
          Adds a Turn Listener to be notified of changes
 void changeTurn()
          Notifies all listeners that a new turn has started.
 java.util.List getEntries()
          This is the normal method for adding information to the log.
 java.lang.String getLogName()
          Usually a particular LogWriter is going to send more than one message to the log during the life of a program.
protected  void logTurnState(java.lang.String shortMessage)
           
 void removeAllTurnListeners()
           
 void removeTurnListener(TurnListener t)
          Removes a Turn Listener
 void setTotalTurns(int total)
           
 void setTurn(int nextCurrentTurn)
           
 void setTurnsInRound(int turnsPerRound)
           
 java.util.List urgentEntries()
          Normally logs are stored in a FIFO manner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mylisteners

protected java.util.Vector mylisteners

normalLog

protected java.util.Vector normalLog

urgentLog

protected java.util.Vector urgentLog

totalTurns

protected int totalTurns

currentTurn

protected int currentTurn

turnsInRound

protected int turnsInRound
Constructor Detail

TurnDispatcher

public TurnDispatcher(int total,
                      int current,
                      int turnsRound)
Creates a new TurnDispatcher. Usually there should be only one in a game.

Parameters:
total - Total Number of Turns
current - The Current Turn
turnsRound - The Number of Turns Per Round. If you have five players and want to give each player three turns in the game then you should make sure you set the Turns Per Round to to Five and the Total Number of Turns to Fiftreen.
Method Detail

addTurnListener

public void addTurnListener(TurnListener t)
Adds a Turn Listener to be notified of changes

Parameters:
t - to be added

removeTurnListener

public void removeTurnListener(TurnListener t)
Removes a Turn Listener

Parameters:
t - to be removed

removeAllTurnListeners

public void removeAllTurnListeners()

setTurn

public void setTurn(int nextCurrentTurn)
Parameters:
nextCurrentTurn - Should be a positive number.

setTurnsInRound

public void setTurnsInRound(int turnsPerRound)

setTotalTurns

public void setTotalTurns(int total)
Parameters:
total - New total number of turns.

changeTurn

public void changeTurn()
Notifies all listeners that a new turn has started. Then notifies all listeners that it has ended.


logTurnState

protected void logTurnState(java.lang.String shortMessage)
Parameters:
shortMessage - to Accompany the log entry

getLogName

public java.lang.String getLogName()
Description copied from interface: LogWriter
Usually a particular LogWriter is going to send more than one message to the log during the life of a program. To avoid constantly sending the sender's name during updates a LogWriter should identify itself through this message.

Specified by:
getLogName in interface LogWriter
Returns:
Descriptive name of the reporting component.
See Also:
LogWriter.getLogName()

getEntries

public java.util.List getEntries()
Description copied from interface: LogWriter
This is the normal method for adding information to the log.

Specified by:
getEntries in interface LogWriter
See Also:
LogWriter.getEntries()

urgentEntries

public java.util.List urgentEntries()
Description copied from interface: LogWriter
Normally logs are stored in a FIFO manner. Using this method will give your message the opportunity to reach the highest point in the log.

Specified by:
urgentEntries in interface LogWriter
Returns:
A List of urgent entires for the log
See Also:
LogWriter.urgentEntries()