talx x1.0.5

talx.games
Class Game

java.lang.Object
  extended bytalx.games.Game
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
HelpDeskGame, SurveyGame, TechGame

public abstract class Game
extends java.lang.Object
implements java.io.Serializable

Holds the current GameState, and provides handler and view factory methods. Implementation classes should only implement the getView and getHandler factory methods. Game instances are produced by the system from the service class's handler method as needed. Game constructors can take parameters that configure the view and handler factories. That is, the Game constructor parameters may determine which view and handler classes are returned. However, the GameHandler class itself should have a no-argument constructor, and the view should get its settings from the MailSystemDesktop, Settings objects.

See Also:
Game Service Provider Interface Documentation, Serialized Form

Field Summary
protected  boolean isSynchronized
          Indicates that the setState method should require synchronization.
 
Constructor Summary
Game(Player p, GameManager gm)
           
 
Method Summary
 void addGameListener(GameListener gml)
          This method adds a new listener to events fired by this Game.
 boolean equals(Game other)
          This method compares two Games and returns true if their String representations are equal.
 void fireLocalModelChange()
          Fires event to alert listeners that the game state has been changed by the local user.
 void fireLocalModelChange(GameState gs)
          Convenience method for setState(gs) followed by fireLocalModelChange().
 void fireRemoteModelChange()
          Fires event to alert listeners that the game state has been changed by the remote user.
 void fireRemoteModelChange(GameState gs)
          Convenience method for setState(gs) followed by fireRemoteModelChange().
 GameManager getGameManager()
           
abstract  GameHandler getHandler()
          Returns the handler for this Game.
 Player getPlayer()
           
 GameState getState()
          Returns the current state of this Game.
abstract  GameView getView(MailSystemDesktop ms, Settings settings)
          Returns the view associated with this Game.
 void removeGameListener(GameListener gml)
          This method removes a listener from the list of listeners to this Game.
 void setState(GameState state)
          Sets the current state of this Game.
 java.lang.String toString()
          Returns the player's ID for this game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isSynchronized

protected boolean isSynchronized
Indicates that the setState method should require synchronization. Subclasses of Game should set this to true if they want to require synchronized setState calls. The default value is false. if this is set to true, then any call to setState that does not hold a monitor lock on this object will not succeed.

Constructor Detail

Game

public Game(Player p,
            GameManager gm)
Method Detail

getPlayer

public Player getPlayer()

getView

public abstract GameView getView(MailSystemDesktop ms,
                                 Settings settings)
Returns the view associated with this Game. This method should just return a newly created implementation object of GameView that is capable of displaying this type of game. The parameters are included for the view to conform to the look and feel of the current system.


getHandler

public abstract GameHandler getHandler()
Returns the handler for this Game. As with all ActionHandlers, the returned object should be stateless, and obtain all state information from the object returned by getState. For this reason, the game handler returned is usually a singleton.


getState

public final GameState getState()
Returns the current state of this Game. This method should not be overridden by subclasses.


setState

public final void setState(GameState state)
Sets the current state of this Game. After calling this method, GameHandlers are expected to call one of the fire model change events before finishing. This method can be called many times, but the views and persistent storage of this game is dependent on the fire model change calls. This method should not be overridden by subclasses.

Parameters:
state - The desired state of this Game.
Throws:
java.lang.IllegalMonitorStateException - if isSynchronized is true and this method is being called without first acquiring a monitor lock. This method cannot simply acquire the lock itself because the lock should be acquired prior to issuing getState() and released subsequent to issuing setState(), which must be handled in the broader context.

addGameListener

public final void addGameListener(GameListener gml)
This method adds a new listener to events fired by this Game. Subsequent calls with the same listener will not result in duplicate event notifications.

Parameters:
gml - The listener that wants to hear events fired by this Game.

removeGameListener

public final void removeGameListener(GameListener gml)
This method removes a listener from the list of listeners to this Game.

Parameters:
gml - The listener that wants to unsubscribe from our listener list.

fireLocalModelChange

public final void fireLocalModelChange()
Fires event to alert listeners that the game state has been changed by the local user.


fireRemoteModelChange

public final void fireRemoteModelChange()
Fires event to alert listeners that the game state has been changed by the remote user.


fireLocalModelChange

public void fireLocalModelChange(GameState gs)
Convenience method for setState(gs) followed by fireLocalModelChange().


fireRemoteModelChange

public void fireRemoteModelChange(GameState gs)
Convenience method for setState(gs) followed by fireRemoteModelChange().


getGameManager

public final GameManager getGameManager()

equals

public boolean equals(Game other)
This method compares two Games and returns true if their String representations are equal.

Parameters:
other - The Game that is to be compared to this.

toString

public java.lang.String toString()
Returns the player's ID for this game.


talx x1.0.5

© 2001-2005 University of Oregon.
Eugene OR 97403, U.S.A. All Rights Reserved.