com.threerings.parlor.game.data
Class GameObject

java.lang.Object
  extended by com.threerings.presents.dobj.DObject
      extended by com.threerings.crowd.data.PlaceObject
          extended by com.threerings.parlor.game.data.GameObject
All Implemented Interfaces:
SpeakObject, Streamable
Direct Known Subclasses:
CardGameObject, PuzzleObject

public class GameObject
extends 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
PlaceObject.ManagerCaller
 
Nested classes/interfaces inherited from interface com.threerings.crowd.chat.data.SpeakObject
SpeakObject.ListenerOp
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
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.
 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 class com.threerings.presents.dobj.DObject
_accessors, _atable, _controller, _deathWish, _listeners, _locattrs, _locks, _oid, _omgr, _scount, _subs, _tcancelled, _tcount, _tevent
 
Constructor Summary
GameObject()
           
 
Method Summary
 int getActivePlayerCount()
          Returns the number of active players in the game.
 int getPlayerCount()
          Returns the number of players in the game.
 int getPlayerIndex(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.
protected  boolean isActivePlayerStatus(int playerStatus)
          Used by isActivePlayer(int) to determine if the supplied status is associated with an active player (one that has not resigned from the game and/or left the game room).
 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(Name[] value)
          Requests that the players field be set to the specified value.
 void setPlayersAt(Name value, int index)
          Requests that the indexth 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 indexth 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 indexth element of winners field be set to the specified value.
protected  void which(StringBuilder buf)
           
 
Methods inherited from class com.threerings.crowd.data.PlaceObject
addToOccupantInfo, addToOccupants, applyToListeners, 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, clearLock, clearTransaction, commitTransaction, createAccessors, destroy, getAccessController, getAccessor, getAttribute, getListenerIndex, getLocal, getLocals, getManager, getOid, getSet, inTransaction, isActive, isAuthoritative, notifyListeners, notifyProxies, postEvent, postMessage, postMessage, readField__oid, releaseLock, removeFromSet, removeListener, removeSubscriber, requestAttributeChange, requestAttributeChange, requestElementUpdate, requestElementUpdate, requestEntryAdd, requestEntryRemove, requestEntryUpdate, requestEntryUpdate, requestOidAdd, requestOidAdd, requestOidRemove, requestOidRemove, setAccessController, setAttribute, setDestroyOnLastSubscriberRemoved, setLocal, setManager, setOid, startTransaction, toString, toString, updateSet, which, writeField__oid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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 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(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.


isActivePlayerStatus

protected boolean isActivePlayerStatus(int playerStatus)
Used by isActivePlayer(int) to determine if the supplied status is associated with an active player (one that has not resigned from the game and/or left the game room).


which

protected void which(StringBuilder buf)
Overrides:
which in class DObject

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(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(Name value,
                                   int index)
Requests that the indexth 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 indexth 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 indexth 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.