com.threerings.parlor.card.server
Class CardGameManager

java.lang.Object
  extended by com.threerings.crowd.server.PlaceManager
      extended by com.threerings.parlor.game.server.GameManager
          extended by com.threerings.parlor.card.server.CardGameManager
All Implemented Interfaces:
SpeakHandler.SpeakerValidator, CardCodes, ParlorCodes, GameCodes, PlayManager, TurnGameManager, InvocationCodes, ChangeListener, MessageListener

public class CardGameManager
extends GameManager
implements TurnGameManager, CardCodes

A manager class for card games. Handles common functions like dealing hands of cards to all players.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.threerings.crowd.server.PlaceManager
PlaceManager.DelegateOp, PlaceManager.MessageHandler
 
Field Summary
protected  CardGameObject _cardgameobj
          The card game object.
protected  int[] _oldPlayerOids
          The oids of the players from our now-ended game.
 
Fields inherited from class com.threerings.parlor.game.server.GameManager
_AIs, _aiTicker, _committedState, _gameconfig, _gameEndTracker, _gameobj, _noShowInterval, _pendingOids, _playerCount, _playerOids, _postponedStart, _startmsgs, _stateListener, _tickInterval, AI_TICK_DELAY, DEFAULT_NOSHOW_DELAY, TICK_DELAY
 
Fields inherited from class com.threerings.crowd.server.PlaceManager
_bodyUpdater, _config, _deathListener, _delegates, _dispatcher, _dispatcherFinders, _injector, _invmgr, _locator, _marshallers, _msghandlers, _occInfo, _occListener, _omgr, _plobj, _registry, _shutdownInterval
 
Fields inherited from interface com.threerings.parlor.card.data.CardCodes
ACE, BLACK_JOKER, CLUBS, DIAMONDS, HEARTS, JACK, KING, QUEEN, RED_JOKER, SPADES
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Fields inherited from interface com.threerings.parlor.data.ParlorCodes
ALREADY_AT_TABLE, BANNED_FROM_TABLE, GAME_ALREADY_STARTED, INVALID_TABLE_POSITION, INVITATION_ACCEPTED, INVITATION_COUNTERED, INVITATION_REFUSED, INVITEE_NOT_ONLINE, MUST_BE_CREATOR, NO_SELF_BOOT, NO_SUCH_TABLE, NOT_AT_TABLE, PARLOR_GROUP, TABLE_POSITION_OCCUPIED
 
Fields inherited from interface com.threerings.parlor.game.data.GameCodes
GAME_CHAT_TYPE, GAME_MESSAGE_BUNDLE, PLAYER_KNOCKED_OUT, WINNERS_AND_LOSERS
 
Constructor Summary
CardGameManager()
           
 
Method Summary
 Hand dealHand(Deck deck, int size, int playerIndex)
          Deals a hand of cards to the player at the specified index from the given Deck.
 Hand[] dealHands(Deck deck, int size)
          Deals a hand of cards to each player from the specified Deck.
protected  void didStartup()
           
protected  void gameDidEnd()
          Called after the game has transitioned to the GameObject.GAME_OVER state.
protected  boolean gameWillRematch()
          Derived classes can override this method and take any action needed prior to a game rematch.
 ClientObject getClientObject(int pidx)
          Returns the client object corresponding to the specified player index, or null if the position is not occupied by a player.
 int getPlayerIndex(ClientObject client)
          Gets the player index of the specified client object, or -1 if the client object does not represent a player.
protected  void notifyCardsTransferred(int fromPlayerIdx, int toPlayerIdx, int cards)
          Notifies everyone in the room (other than the sender and the receiver) that a set of cards have been transferred.
 void rematchGame()
          This should be called to start a rematched game.
 void transferCardsBetweenPlayers(int[] toPlayerIndices, Card[][] cards)
          Sends sets of cards between players simultaneously.
 void transferCardsBetweenPlayers(int fromPlayerIdx, int toPlayerIdx, Card[] cards)
          Sends a set of cards from one player to another.
 void turnDidEnd()
          Called when the turn was ended.
 void turnDidStart()
          Called when we have started the next turn.
 void turnWillStart()
          Called when we are about to start the next turn.
 
Methods inherited from class com.threerings.parlor.game.server.GameManager
addPlayer, addPlayerAt, allPlayersReady, announcePlayerGameOver, assignWinners, bodyLeft, cancelGame, checkForNoShows, checkShutdownInterval, checkWritePermission, didInit, didShutdown, endGame, endPlayerGame, gameDidStart, gameWasCancelled, gameWillEnd, gameWillReset, gameWillStart, getGameConfig, getGameId, getMatchType, getNoShowTime, getPlayer, getPlayerCount, getPlayerDisplayName, getPlayerGameOverMessage, getPlayerIndex, getPlayerName, getPlayerOid, getPlayerPersistentId, getPlayerPersistentId, getPlayerSlots, getPresentPlayerIndex, getSessionId, handlePartialNoShow, isActivePlayer, isAgent, isAI, isPlayer, needsAITick, needsNoShowTimer, occupantInRoom, placeBecameEmpty, playerGameDidEnd, playerIsReady, playerReady, playersAllHere, playerWasAdded, playerWasRemoved, playerWasReplaced, removePlayer, replacePlayer, reportPlayerKnockedOut, reportWinnersAndLosers, resetGame, setAI, shouldConcludeGame, shouldEndGame, startAITicker, startGame, startWithoutHumans, stateDidChange, stopAITicker, systemMessage, systemMessage, tick, tickAI, tickAIs
 
Methods inherited from class com.threerings.crowd.server.PlaceManager
addDelegate, addDispatcher, addOccupantInfo, addProvider, applyToDelegates, applyToOccupants, bodyEntered, bodyUpdated, bodyWillEnter, bodyWillLeave, cancelShutdowner, checkPermissions, createPlaceObject, createSpeakHandler, getAccessController, getConfig, getLocation, getPlaceObject, getPlaceObjectClass, idleUnloadPeriod, init, isValidSpeaker, messageReceived, permissionsFailed, ratifyBodyEntry, registerMessageHandler, shouldCreateSpeakService, shouldDeclareEmpty, shutdown, startup, toString, toString, updateOccupantInfo, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.threerings.parlor.turn.server.TurnGameManager
getPlayerCount, getPlayerIndex, getPlayerName, isActivePlayer
 

Field Detail

_cardgameobj

protected CardGameObject _cardgameobj
The card game object.


_oldPlayerOids

protected int[] _oldPlayerOids
The oids of the players from our now-ended game.

Constructor Detail

CardGameManager

public CardGameManager()
Method Detail

didStartup

protected void didStartup()
Overrides:
didStartup in class GameManager

turnWillStart

public void turnWillStart()
Description copied from interface: TurnGameManager
Called when we are about to start the next turn. Implementations can do whatever pre-start turn activities need to be done.

Specified by:
turnWillStart in interface TurnGameManager

turnDidStart

public void turnDidStart()
Description copied from interface: TurnGameManager
Called when we have started the next turn. Implementations can do whatever post-start turn activities need to be done.

Specified by:
turnDidStart in interface TurnGameManager

turnDidEnd

public void turnDidEnd()
Description copied from interface: TurnGameManager
Called when the turn was ended. Implementations can perform any post-turn processing (like updating scores, etc.).

Specified by:
turnDidEnd in interface TurnGameManager

gameDidEnd

protected void gameDidEnd()
Description copied from class: GameManager
Called after the game has transitioned to the GameObject.GAME_OVER state. Derived classes should override this to perform any post-game activities, but should be sure to call super.gameDidEnd().

Overrides:
gameDidEnd in class GameManager

rematchGame

public void rematchGame()
This should be called to start a rematched game. It just starts the current game anew, but provides a mechanism for derived classes to do special things when there is a rematch.


gameWillRematch

protected boolean gameWillRematch()
Derived classes can override this method and take any action needed prior to a game rematch. If the rematch needs to be vetoed for any reason, they can return false from this method and the rematch will be aborted.


dealHand

public Hand dealHand(Deck deck,
                     int size,
                     int playerIndex)
Deals a hand of cards to the player at the specified index from the given Deck.

Parameters:
deck - the deck from which to deal
size - the size of the hand to deal
playerIndex - the index of the target player
Returns:
the hand dealt to the player, or null if the deal was canceled because the deck did not contain enough cards

dealHands

public Hand[] dealHands(Deck deck,
                        int size)
Deals a hand of cards to each player from the specified Deck.

Parameters:
deck - the deck from which to deal
size - the size of the hands to deal
Returns:
the array of hands dealt to each player, or null if the deal was canceled because the deck did not contain enough cards

getPlayerIndex

public int getPlayerIndex(ClientObject client)
Gets the player index of the specified client object, or -1 if the client object does not represent a player. If the game has ended, looks through the players of the now-ended game.


getClientObject

public ClientObject getClientObject(int pidx)
Returns the client object corresponding to the specified player index, or null if the position is not occupied by a player.


transferCardsBetweenPlayers

public void transferCardsBetweenPlayers(int fromPlayerIdx,
                                        int toPlayerIdx,
                                        Card[] cards)
Sends a set of cards from one player to another.

Parameters:
fromPlayerIdx - the index of the player sending the cards
toPlayerIdx - the index of the player receiving the cards
cards - the cards to be exchanged

transferCardsBetweenPlayers

public void transferCardsBetweenPlayers(int[] toPlayerIndices,
                                        Card[][] cards)
Sends sets of cards between players simultaneously. Each player is guaranteed to receive the notification of cards received after the notification of cards sent. The length of the arrays passed must be equal to the player count.

Parameters:
toPlayerIndices - for each player, the index of the player to transfer cards to
cards - for each player, the cards to transfer

notifyCardsTransferred

protected void notifyCardsTransferred(int fromPlayerIdx,
                                      int toPlayerIdx,
                                      int cards)
Notifies everyone in the room (other than the sender and the receiver) that a set of cards have been transferred.

Parameters:
fromPlayerIdx - the index of the player sending the cards
toPlayerIdx - the index of the player receiving the cards
cards - the number of cards sent