com.threerings.parlor.game.data

## Class GameObject

- java.lang.Object
- - com.threerings.presents.dobj.DObject
  - - com.threerings.crowd.data.PlaceObject
    - - com.threerings.parlor.game.data.GameObject

All Implemented Interfaces:
  com.threerings.crowd.chat.data.SpeakObject, com.threerings.io.Streamable

Direct Known Subclasses:
  CardGameObject, PuzzleObject

    public class GameObject
    extends com.threerings.crowd.data.PlaceObject

A game object hosts the shared data associated with a game played by one or more players. The game object extends the place object so that the game can act as a place where players actually go when playing the game. Only very basic information is maintained in the base game object. It serves as the base for a hierarchy of game object derivatives that handle basic gameplay for a suite of different game types (ie. turn based games, party games, board games, card games, etc.).

### Nested Class Summary

### Nested classes/interfaces inherited from class com.threerings.crowd.data.PlaceObject

`com.threerings.crowd.data.PlaceObject.ManagerCaller`

### Nested classes/interfaces inherited from interface com.threerings.crowd.chat.data.SpeakObject

`com.threerings.crowd.chat.data.SpeakObject.ListenerOp`

### Nested classes/interfaces inherited from interface com.threerings.io.Streamable

`com.threerings.io.Streamable.Closure`

### Field Summary

Fields
`static int` `CANCELLED` A game state constant indicating that the game was cancelled.
`static int` `GAME_OVER` A game state constant indicating that the game ended normally.
`static int` `IN_PLAY` A game state constant indicating that the game is in play.
`static String` `IS_PRIVATE` The field name of the `isPrivate` field.
`static String` `IS_RATED` The field name of the `isRated` field.
`boolean` `isPrivate` Indicates whether the game is "private".
`boolean` `isRated` Indicates whether or not this game is rated.
`static int` `PLAYER_IN_PLAY` The player status constant for a player whose game is in play.
`static int` `PLAYER_LEFT_GAME` The player status constant for a player whose has been knocked out of the game.
`static String` `PLAYER_STATUS` The field name of the `playerStatus` field.
`com.threerings.util.Name[]` `players` The usernames of the players involved in this game.
`static String` `PLAYERS` The field name of the `players` field.
`int[]` `playerStatus` If null, indicates that all present players are active, or for more complex games can be non-null to indicate the current status of each player in the game.
`static int` `PRE_GAME` A game state constant indicating that the game has not yet started and is still awaiting the arrival of all of the players.
`static String` `SESSION_ID` The field name of the `sessionId` field.
`int` `sessionId` A unique identifier for each game session.
`int` `state` The game state, one of `PRE_GAME`, `IN_PLAY`, `GAME_OVER`, or `CANCELLED`.
`static String` `STATE` The field name of the `state` field.
`boolean[]` `winners` Whether each player in the game is a winner, or null if the game is not yet over.
`static String` `WINNERS` The field name of the `winners` field.

### Fields inherited from class com.threerings.crowd.data.PlaceObject

`manager, OCCUPANT_INFO, occupantInfo, occupants, OCCUPANTS, SPEAK_SERVICE, speakService`

### Fields inherited from interface com.threerings.crowd.chat.data.SpeakObject

`DEFAULT_IDENTIFIER`

### Constructor Summary

Constructors
Constructor and Description
`GameObject()`

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `getActivePlayerCount()` Returns the number of active players in the game.
`int` `getPlayerCount()` Returns the number of players in the game.
`int` `getPlayerIndex(com.threerings.util.Name username)` Returns the player index of the given user in the game, or `-1` if the player is not involved in the game.
`int` `getWinnerCount()` Returns the number of winners for this game, or `0` if the winners array is not populated, e.g., the game is not yet over.
`int` `getWinnerIndex()` Returns the winner index of the first winning player for this game, or `-1` if there are no winners or the winners array is not yet assigned.
`boolean` `isActivePlayer(int pidx)` Returns whether the given player is still an active player in the game.
`boolean` `isDraw()` Returns true if the game is ended in a draw.
`boolean` `isInPlay()` Returns whether the game is in play.
`boolean` `isOccupiedPlayer(int pidx)` Returns whether the given player index in the game is occupied.
`boolean` `isWinner(int pidx)` Returns whether the given player index is a winner, or false if the winners are not yet assigned.
`void` `setIsPrivate(boolean value)` Requests that the `isPrivate` field be set to the specified value.
`void` `setIsRated(boolean value)` Requests that the `isRated` field be set to the specified value.
`void` `setPlayers(com.threerings.util.Name[] value)` Requests that the `players` field be set to the specified value.
`void` `setPlayersAt(com.threerings.util.Name value, int index)` Requests that the `index`th element of `players` field be set to the specified value.
`void` `setPlayerStatus(int[] value)` Requests that the `playerStatus` field be set to the specified value.
`void` `setPlayerStatusAt(int value, int index)` Requests that the `index`th element of `playerStatus` field be set to the specified value.
`void` `setSessionId(int value)` Requests that the `sessionId` field be set to the specified value.
`void` `setState(int value)` Requests that the `state` field be set to the specified value.
`void` `setWinners(boolean[] value)` Requests that the `winners` field be set to the specified value.
`void` `setWinnersAt(boolean value, int index)` Requests that the `index`th element of `winners` field be set to the specified value.

### Methods inherited from class com.threerings.crowd.data.PlaceObject

`addToOccupantInfo, addToOccupants, applyToListeners, getChatIdentifier, getOccupantInfo, initManagerCaller, removeFromOccupantInfo, removeFromOccupants, setOccupantInfo, setSpeakService, shouldBroadcast, updateOccupantInfo`

### Methods inherited from class com.threerings.presents.dobj.DObject

`acquireLock, addListener, addListener, addSubscriber, addToSet, cancelTransaction, changeAttribute, checkPermissions, checkPermissions, commitTransaction, destroy, getAccessController, getAttribute, getLocal, getLocals, getManager, getOid, getSet, inTransaction, isActive, notifyListeners, notifyProxies, postEvent, postMessage, postMessage, releaseLock, removeFromSet, removeListener, removeSubscriber, setAccessController, setAttribute, setDestroyOnLastSubscriberRemoved, setLocal, setManager, setOid, startTransaction, toString, updateSet, which`

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

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

### Field Detail

#### STATE

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String STATE

The field name of the `state` field.

See Also:
  Constant Field Values

#### IS_RATED

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String IS_RATED

The field name of the `isRated` field.

See Also:
  Constant Field Values

#### IS_PRIVATE

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String IS_PRIVATE

The field name of the `isPrivate` field.

See Also:
  Constant Field Values

#### PLAYERS

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String PLAYERS

The field name of the `players` field.

See Also:
  Constant Field Values

#### WINNERS

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String WINNERS

The field name of the `winners` field.

See Also:
  Constant Field Values

#### SESSION_ID

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String SESSION_ID

The field name of the `sessionId` field.

See Also:
  Constant Field Values

#### PLAYER_STATUS

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public static final String PLAYER_STATUS

The field name of the `playerStatus` field.

See Also:
  Constant Field Values

#### PRE_GAME

    public static final int PRE_GAME

A game state constant indicating that the game has not yet started and is still awaiting the arrival of all of the players.

See Also:
  Constant Field Values

#### IN_PLAY

    public static final int IN_PLAY

A game state constant indicating that the game is in play.

See Also:
  Constant Field Values

#### GAME_OVER

    public static final int GAME_OVER

A game state constant indicating that the game ended normally.

See Also:
  Constant Field Values

#### CANCELLED

    public static final int CANCELLED

A game state constant indicating that the game was cancelled.

See Also:
  Constant Field Values

#### PLAYER_IN_PLAY

    public static final int PLAYER_IN_PLAY

The player status constant for a player whose game is in play.

See Also:
  Constant Field Values

#### PLAYER_LEFT_GAME

    public static final int PLAYER_LEFT_GAME

The player status constant for a player whose has been knocked out of the game. NOTE: This can include a player choosing to leave a game prematurely.

See Also:
  Constant Field Values

#### state

    public int state

The game state, one of `PRE_GAME`, `IN_PLAY`, `GAME_OVER`, or `CANCELLED`.

#### isRated

    public boolean isRated

Indicates whether or not this game is rated.

#### isPrivate

    public boolean isPrivate

Indicates whether the game is "private".

#### players

    public com.threerings.util.Name[] players

The usernames of the players involved in this game.

#### winners

    public boolean[] winners

Whether each player in the game is a winner, or null if the game is not yet over.

#### sessionId

    public int sessionId

A unique identifier for each game session. Every time the game is started, this value will be incremented to provide a unique identifier for that particular session.

#### playerStatus

    public int[] playerStatus

If null, indicates that all present players are active, or for more complex games can be non-null to indicate the current status of each player in the game. The status value is one of `PLAYER_LEFT_GAME` or `PLAYER_IN_PLAY`.

Subclasses of GameObject may use other means to determine a player's status in the game, so call `isActivePlayer(int)` to see if a player is still participating in a game.

### Constructor Detail

#### GameObject

    public GameObject()

### Method Detail

#### getPlayerCount

    public int getPlayerCount()

Returns the number of players in the game.

#### getActivePlayerCount

    public int getActivePlayerCount()

Returns the number of active players in the game.

#### isActivePlayer

    public boolean isActivePlayer(int pidx)

Returns whether the given player is still an active player in the game. (Ie. whether or not they are still participating.)

#### getPlayerIndex

    public int getPlayerIndex(com.threerings.util.Name username)

Returns the player index of the given user in the game, or `-1` if the player is not involved in the game.

#### isInPlay

    public boolean isInPlay()

Returns whether the game is in play. A game that is not in play could either be awaiting players, ended, or cancelled.

#### isOccupiedPlayer

    public boolean isOccupiedPlayer(int pidx)

Returns whether the given player index in the game is occupied.

#### isWinner

    public boolean isWinner(int pidx)

Returns whether the given player index is a winner, or false if the winners are not yet assigned.

#### getWinnerCount

    public int getWinnerCount()

Returns the number of winners for this game, or `0` if the winners array is not populated, e.g., the game is not yet over.

#### isDraw

    public boolean isDraw()

Returns true if the game is ended in a draw.

#### getWinnerIndex

    public int getWinnerIndex()

Returns the winner index of the first winning player for this game, or `-1` if there are no winners or the winners array is not yet assigned. This is only likely to be useful for games that are known to have a single winner.

#### setState

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setState(int value)

Requests that the `state` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setIsRated

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setIsRated(boolean value)

Requests that the `isRated` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setIsPrivate

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setIsPrivate(boolean value)

Requests that the `isPrivate` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setPlayers

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setPlayers(com.threerings.util.Name[] value)

Requests that the `players` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setPlayersAt

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setPlayersAt(com.threerings.util.Name value,
                                                                                              int index)

Requests that the `index`th element of `players` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setWinners

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setWinners(boolean[] value)

Requests that the `winners` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setWinnersAt

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setWinnersAt(boolean value,
                                                                                              int index)

Requests that the `index`th element of `winners` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setSessionId

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setSessionId(int value)

Requests that the `sessionId` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setPlayerStatus

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setPlayerStatus(int[] value)

Requests that the `playerStatus` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.

#### setPlayerStatusAt

    @Generated(value="com.threerings.presents.tools.GenDObjectTask")
    public void setPlayerStatusAt(int value,
                                                                                                   int index)

Requests that the `index`th element of `playerStatus` field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.