com.threerings.parlor.game.client

## Class GameController

- java.lang.Object
- - com.samskivert.swing.Controller
  - - com.threerings.crowd.client.PlaceController
    - - com.threerings.parlor.game.client.GameController

All Implemented Interfaces:
  com.threerings.presents.dobj.AttributeChangeListener, com.threerings.presents.dobj.ChangeListener, ActionListener, EventListener

Direct Known Subclasses:
  CardGameController, PuzzleController

    public abstract class GameController
    extends com.threerings.crowd.client.PlaceController
    implements com.threerings.presents.dobj.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

`com.threerings.crowd.client.PlaceController.DelegateOp`

### Field Summary

### Fields inherited from class com.samskivert.swing.Controller

`DISPATCHER`

### Constructor Summary

Constructors
Constructor and Description
`GameController()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `attributeChanged(com.threerings.presents.dobj.AttributeChangedEvent event)`
`void` `didLeavePlace(com.threerings.crowd.data.PlaceObject plobj)` Removes our listener registration from the game object and cleans house.
`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(com.threerings.crowd.util.CrowdContext ctx, com.threerings.crowd.data.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.
`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.
`void` `systemMessage(String bundle, String msg)` A way for controllers to display a game-related system message.
`void` `willEnterPlace(com.threerings.crowd.data.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

`getPlaceConfig, getPlaceView, mayLeavePlace`

### Methods inherited from class com.samskivert.swing.Controller

`actionPerformed, configureAction, createActionButton, handleAction, handleAction, handleAction, postAction, postAction, postAction, setControlledPanel, wasAdded, wasRemoved`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GameController

    public GameController()

### Method Detail

#### init

    public void init(com.threerings.crowd.util.CrowdContext ctx,
                     com.threerings.crowd.data.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 `com.threerings.crowd.client.PlaceController`
Parameters:
  `ctx` - the client context.
  `config` - the configuration of the game we are intended to control.

#### willEnterPlace

    public void willEnterPlace(com.threerings.crowd.data.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 `com.threerings.crowd.client.PlaceController`

#### didLeavePlace

    public void didLeavePlace(com.threerings.crowd.data.PlaceObject plobj)

Removes our listener registration from the game object and cleans house.

Overrides:
  `didLeavePlace` in class `com.threerings.crowd.client.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 `com.threerings.crowd.client.PlaceController`

#### systemMessage

    public void systemMessage(String bundle,
                              String msg)

A way for controllers to display a game-related system message.

#### attributeChanged

    public void attributeChanged(com.threerings.presents.dobj.AttributeChangedEvent event)

Specified by:
  `attributeChanged` in interface `com.threerings.presents.dobj.AttributeChangeListener`