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:
com.threerings.crowd.chat.server.SpeakHandler.SpeakerValidator, CardCodes, ParlorCodes, GameCodes, PlayManager, TurnGameManager, com.threerings.presents.data.InvocationCodes, com.threerings.presents.dobj.ChangeListener, com.threerings.presents.dobj.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
com.threerings.crowd.server.PlaceManager.DelegateOp, com.threerings.crowd.server.PlaceManager.MessageHandler
 
Field Summary
 
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.
 com.threerings.presents.data.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(com.threerings.presents.data.ClientObject client)
          Gets the player index of the specified client object, or -1 if the client object does not represent a player.
 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, cancelGame, checkWritePermission, endGame, endPlayerGame, getGameConfig, getGameId, getMatchType, getPlayer, getPlayerCount, getPlayerDisplayName, getPlayerIndex, getPlayerName, getPlayerOid, getPlayerPersistentId, getPlayerPersistentId, getPlayerSlots, getPresentPlayerIndex, getSessionId, isActivePlayer, isAgent, isAI, isPlayer, occupantInRoom, playerIsReady, playerReady, removePlayer, replacePlayer, resetGame, setAI, shouldConcludeGame, startGame, systemMessage, systemMessage
 
Methods inherited from class com.threerings.crowd.server.PlaceManager
addDelegate, applyToDelegates, applyToOccupants, bodyWillEnter, bodyWillLeave, checkPermissions, getConfig, getLocation, getPlaceObject, init, isValidSpeaker, messageReceived, ratifyBodyEntry, registerMessageHandler, shutdown, startup, toString, updateOccupantInfo, where
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.threerings.parlor.turn.server.TurnGameManager
getPlayerCount, getPlayerIndex, getPlayerName, isActivePlayer
 

Constructor Detail

CardGameManager

public CardGameManager()
Method Detail

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

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.


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(com.threerings.presents.data.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 com.threerings.presents.data.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


Copyright © 2011. All Rights Reserved.