com.threerings.parlor.game.client
Class GameController

java.lang.Object
  extended by com.samskivert.swing.Controller
      extended by com.threerings.crowd.client.PlaceController
          extended by com.threerings.parlor.game.client.GameController
All Implemented Interfaces:
AttributeChangeListener, ChangeListener, ActionListener, EventListener
Direct Known Subclasses:
CardGameController, PuzzleController

public abstract class GameController
extends PlaceController
implements AttributeChangeListener

The game controller manages the flow and control of a game on the client side. This class serves as the root of a hierarchy of controller classes that aim to provide functionality shared between various similar games. The base controller provides functionality for starting and ending the game and for calculating ratings adjustments when a game ends normally. It also handles the basic house keeping like subscription to the game object and dispatch of commands and distributed object events.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.crowd.client.PlaceController
PlaceController.DelegateOp
 
Nested classes/interfaces inherited from class com.samskivert.swing.Controller
Controller.ActionInvoker
 
Field Summary
protected  GameConfig _config
          Our game configuration information.
protected  ParlorContext _ctx
          A reference to the active parlor context.
protected  boolean _gameOver
          A local flag overriding the game over state for situations where the client knows the game is over before the server has transitioned the game object accordingly.
protected  GameObject _gobj
          A reference to the game object for the game that we're controlling.
 
Fields inherited from class com.threerings.crowd.client.PlaceController
_delegates, _plobj, _view
 
Fields inherited from class com.samskivert.swing.Controller
DISPATCHER
 
Constructor Summary
GameController()
           
 
Method Summary
 void attributeChanged(AttributeChangedEvent event)
           
 void didLeavePlace(PlaceObject plobj)
          Removes our listener registration from the game object and cleans house.
protected  void gameDidEnd()
          Called when the game transitions to the GAME_OVER state.
protected  void gameDidStart()
          Called when the game transitions to the IN_PLAY state.
protected  void gameWasCancelled()
          Called when the game was cancelled for some reason.
protected  void gameWillReset()
          Called to give derived classes a chance to display animations, send a final packet, or do any other business they care to do when the game is about to reset.
 int getMatchType()
          Convenience method to determine the type of game.
 int getSessionId()
          Returns the unique session identifier for the current gameplay session.
 boolean handleAction(ActionEvent action)
          Handles basic game controller action events.
 void init(CrowdContext ctx, PlaceConfig config)
          Initializes this game controller with the game configuration that was established during the match making process.
 boolean isGameOver()
          Returns whether the game is over.
protected  void playerReady()
          Called after we've entered the game and everything has initialized to notify the server that we, as a player, are ready to play.
 void resetGame()
          Calls gameWillReset(), ends the current game (locally, it does not tell the server to end the game), and waits to receive a reset notification (which is simply an event setting the game state to IN_PLAY even though it's already set to IN_PLAY) from the server which will start up a new game.
 void setGameOver(boolean gameOver)
          Sets the client game over override.
protected  boolean stateDidChange(int state)
          Derived classes can override this method if they add additional game states and should handle transitions to those states, returning true to indicate they were handled and calling super for the normal game states.
 void systemMessage(String bundle, String msg)
          A way for controllers to display a game-related system message.
 void willEnterPlace(PlaceObject plobj)
          Adds this controller as a listener to the game object (thus derived classes need not do so) and lets the game manager know that we are now ready to go.
 
Methods inherited from class com.threerings.crowd.client.PlaceController
addDelegate, applyToDelegates, createPlaceView, createPlaceView, didInit, getPlaceConfig, getPlaceView, mayLeavePlace
 
Methods inherited from class com.samskivert.swing.Controller
actionPerformed, configureAction, createActionButton, generateArguments, handleAction, handleAction, handleAction, postAction, postAction, postAction, setControlledPanel, wasAdded, wasRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ctx

protected ParlorContext _ctx
A reference to the active parlor context.


_config

protected GameConfig _config
Our game configuration information.


_gobj

protected GameObject _gobj
A reference to the game object for the game that we're controlling.


_gameOver

protected boolean _gameOver
A local flag overriding the game over state for situations where the client knows the game is over before the server has transitioned the game object accordingly.

Constructor Detail

GameController

public GameController()
Method Detail

init

public void init(CrowdContext ctx,
                 PlaceConfig config)
Initializes this game controller with the game configuration that was established during the match making process. Derived classes may want to override this method to initialize themselves with game-specific configuration parameters but they should be sure to call super.init in such cases.

Overrides:
init in class PlaceController
Parameters:
ctx - the client context.
config - the configuration of the game we are intended to control.

willEnterPlace

public void willEnterPlace(PlaceObject plobj)
Adds this controller as a listener to the game object (thus derived classes need not do so) and lets the game manager know that we are now ready to go.

Overrides:
willEnterPlace in class PlaceController

didLeavePlace

public void didLeavePlace(PlaceObject plobj)
Removes our listener registration from the game object and cleans house.

Overrides:
didLeavePlace in class PlaceController

getMatchType

public int getMatchType()
Convenience method to determine the type of game.


isGameOver

public boolean isGameOver()
Returns whether the game is over.


setGameOver

public void setGameOver(boolean gameOver)
Sets the client game over override. This is used in situations where we determine that the game is over before the server has informed us of such.


resetGame

public void resetGame()
Calls gameWillReset(), ends the current game (locally, it does not tell the server to end the game), and waits to receive a reset notification (which is simply an event setting the game state to IN_PLAY even though it's already set to IN_PLAY) from the server which will start up a new game. Derived classes should override gameWillReset() to perform any game-specific animations.


getSessionId

public int getSessionId()
Returns the unique session identifier for the current gameplay session.


handleAction

public boolean handleAction(ActionEvent action)
Handles basic game controller action events. Derived classes should be sure to call super.handleAction for events they don't specifically handle.

Overrides:
handleAction in class PlaceController

systemMessage

public void systemMessage(String bundle,
                          String msg)
A way for controllers to display a game-related system message.


attributeChanged

public void attributeChanged(AttributeChangedEvent event)
Specified by:
attributeChanged in interface AttributeChangeListener

stateDidChange

protected boolean stateDidChange(int state)
Derived classes can override this method if they add additional game states and should handle transitions to those states, returning true to indicate they were handled and calling super for the normal game states.


playerReady

protected void playerReady()
Called after we've entered the game and everything has initialized to notify the server that we, as a player, are ready to play.


gameDidStart

protected void gameDidStart()
Called when the game transitions to the IN_PLAY state. This happens when all of the players have arrived and the server starts the game.


gameDidEnd

protected void gameDidEnd()
Called when the game transitions to the GAME_OVER state. This happens when the game reaches some end condition by normal means (is not cancelled or aborted).


gameWasCancelled

protected void gameWasCancelled()
Called when the game was cancelled for some reason.


gameWillReset

protected void gameWillReset()
Called to give derived classes a chance to display animations, send a final packet, or do any other business they care to do when the game is about to reset.