com.threerings.parlor.card.trick.server
Class TrickCardGameManagerDelegate

java.lang.Object
  extended by com.threerings.crowd.server.PlaceManagerDelegate
      extended by com.threerings.parlor.server.PlayManagerDelegate
          extended by com.threerings.parlor.game.server.GameManagerDelegate
              extended by com.threerings.parlor.turn.server.TurnGameManagerDelegate
                  extended by com.threerings.parlor.card.trick.server.TrickCardGameManagerDelegate
All Implemented Interfaces:
TrickCardGameProvider, InvocationProvider

public class TrickCardGameManagerDelegate
extends TurnGameManagerDelegate
implements TrickCardGameProvider

A card game manager delegate for trick-based card games, such as Spades and Hearts.


Field Summary
protected  CardGameObject _cardGame
          The game object as card game.
protected  CardGameManager _cgmgr
          The card game manager.
protected  Deck _deck
          The deck from which cards are dealt.
protected  long _endTrickDelay
          The amount of time to wait before ending the trick.
protected  Interval _endTrickInterval
          Calls endTrick() upon expiration.
protected  Hand[] _hands
          The hands of each player.
protected  TrickCardGameObject _trickCardGame
          The game object as trick card game.
protected  boolean _turnTimedOut
          Whether or not the turn timed out.
protected  Interval _turnTimeoutInterval
          The all-purpose turn timeout interval.
protected static float MINIMUM_TURN_DURATION_SCALE
          Don't let turn duration scales get below this level.
protected static float TURN_DURATION_SCALE_INCREASE
          Turn duration scales increase by this amount each time the player doesn't time out.
protected static float TURN_DURATION_SCALE_REDUCTION
          Reduce turn duration scales by this amount each time the player times out.
 
Fields inherited from class com.threerings.parlor.turn.server.TurnGameManagerDelegate
_tgmgr, _turnGame, _turnIdx
 
Fields inherited from class com.threerings.parlor.server.PlayManagerDelegate
_gmgr
 
Fields inherited from class com.threerings.crowd.server.PlaceManagerDelegate
_invmgr, _omgr, _plmgr
 
Constructor Summary
TrickCardGameManagerDelegate()
           
TrickCardGameManagerDelegate(CardGameManager manager)
          Deprecated. use the zero-argument constructor.
 
Method Summary
protected  boolean anyHandsEmpty()
          Checks whether any hands are empty.
protected  void dealHands()
          Deals hands to the players.
 void didInit(PlaceConfig config)
           
 void didStartup(PlaceObject plobj)
           
 void endHand()
          Ends the hand of cards.
 void endTrick()
          Ends the trick.
 void endTurn()
          Called to end the turn.
 void gameDidEnd()
          Called by the game manager after the game ended.
 void gameDidStart()
          Called when the game has started.
 void gameWillStart()
          Called by the game manager when the game is about to start.
protected  int getRematchRequestCount()
          Returns the number of players currently requesting or accepting a rematch.
protected  void handDidEnd()
          Notifies the object that the hand has ended.
protected  void handDidStart()
          Notifies the object that a new hand has just started.
protected  void handWillEnd()
          Notifies the object that the hand is about to end.
protected  void handWillStart()
          Notifies the object that a new hand is about to start.
protected  void increaseTurnDurationScale(int pidx)
          Increases the specified player's turn duration due to avoiding a time-out.
 void init(PlaceManager plmgr, RootDObjectManager omgr, InvocationManager invmgr)
           
protected  boolean isTrickComplete()
          Checks whether the trick is complete--that is, whether each player has played a card.
protected  Card pickRandomPlayableCard(Hand hand)
          Returns a random playable card from the specified hand.
 void playCard(ClientObject client, Card card, int handSize)
          Handles a TrickCardGameService.playCard(com.threerings.parlor.card.data.Card, int) request.
protected  void playCard(int pidx, Card card)
          Plays a card for a player without error checking.
protected  void prepareDeck()
          Prepares the deck for a new hand of cards.
protected  void reduceTurnDurationScale(int pidx)
          Reduces the specified player's turn duration due to a time-out.
 void requestRematch(ClientObject client)
          Handles a TrickCardGameService.requestRematch() request.
 void sendCardsToPlayer(ClientObject client, int toidx, Card[] cards)
          Handles a TrickCardGameService.sendCardsToPlayer(int, com.threerings.parlor.card.data.Card[]) request.
protected  void sendCardsToPlayer(int fromidx, int toidx, Card[] cards)
          Sends cards between players without error checking.
protected  void setFirstTurnHolder()
          This is called to determine which player will take the first turn.
protected  void setNextTurnHolder()
          This is called to determine which player will next hold the turn.
 void startHand()
          Starts a hand of cards.
 void startTrick()
          Starts a trick.
 void startTurn()
          Called to start the next turn.
protected  void trickDidEnd()
          Notifies the object that the trick has ended.
protected  void trickDidStart()
          Notifies the object that a new trick has started.
protected  void trickWillEnd()
          Notifies the object that the trick is about to end.
protected  void trickWillStart()
          Notifies the object that a new trick is about to start.
protected  void turnTimedOut()
          Called when the current turn times out.
 
Methods inherited from class com.threerings.parlor.turn.server.TurnGameManagerDelegate
assignTurnRandomly, getTurnHolderIndex, isPlayersTurn, playerWasReplaced
 
Methods inherited from class com.threerings.parlor.game.server.GameManagerDelegate
gameWillEnd, gameWillReset, setAI, tickAI
 
Methods inherited from class com.threerings.parlor.server.PlayManagerDelegate
isAgent, isPlayer, verifyIsPlayer, verifyIsPlayerOrAgent, verifyWritePermission
 
Methods inherited from class com.threerings.crowd.server.PlaceManagerDelegate
addDispatcher, addProvider, bodyEntered, bodyLeft, bodyUpdated, didShutdown, placeBecameEmpty, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_turnTimeoutInterval

protected Interval _turnTimeoutInterval
The all-purpose turn timeout interval.


_endTrickInterval

protected Interval _endTrickInterval
Calls endTrick() upon expiration.


_cgmgr

protected CardGameManager _cgmgr
The card game manager.


_trickCardGame

protected TrickCardGameObject _trickCardGame
The game object as trick card game.


_cardGame

protected CardGameObject _cardGame
The game object as card game.


_endTrickDelay

protected long _endTrickDelay
The amount of time to wait before ending the trick.


_deck

protected Deck _deck
The deck from which cards are dealt.


_hands

protected Hand[] _hands
The hands of each player.


_turnTimedOut

protected boolean _turnTimedOut
Whether or not the turn timed out.


TURN_DURATION_SCALE_REDUCTION

protected static final float TURN_DURATION_SCALE_REDUCTION
Reduce turn duration scales by this amount each time the player times out.

See Also:
Constant Field Values

TURN_DURATION_SCALE_INCREASE

protected static final float TURN_DURATION_SCALE_INCREASE
Turn duration scales increase by this amount each time the player doesn't time out.

See Also:
Constant Field Values

MINIMUM_TURN_DURATION_SCALE

protected static final float MINIMUM_TURN_DURATION_SCALE
Don't let turn duration scales get below this level.

See Also:
Constant Field Values
Constructor Detail

TrickCardGameManagerDelegate

public TrickCardGameManagerDelegate()

TrickCardGameManagerDelegate

@Deprecated
public TrickCardGameManagerDelegate(CardGameManager manager)
Deprecated. use the zero-argument constructor.

Method Detail

init

public void init(PlaceManager plmgr,
                 RootDObjectManager omgr,
                 InvocationManager invmgr)
Overrides:
init in class PlaceManagerDelegate

didInit

public void didInit(PlaceConfig config)
Overrides:
didInit in class TurnGameManagerDelegate

didStartup

public void didStartup(PlaceObject plobj)
Overrides:
didStartup in class TurnGameManagerDelegate

gameWillStart

public void gameWillStart()
Description copied from class: GameManagerDelegate
Called by the game manager when the game is about to start.

Overrides:
gameWillStart in class GameManagerDelegate

gameDidStart

public void gameDidStart()
Called when the game has started. Default implementation starts the first hand.

Overrides:
gameDidStart in class TurnGameManagerDelegate

gameDidEnd

public void gameDidEnd()
Description copied from class: GameManagerDelegate
Called by the game manager after the game ended.

Overrides:
gameDidEnd in class GameManagerDelegate

startTurn

public void startTurn()
Description copied from class: TurnGameManagerDelegate
Called to start the next turn. It calls TurnGameManager.turnWillStart() to allow our owning manager to perform any pre-start turn processing, sets the turn holder that was configured either when the game started or when finishing up the last turn, and then calls TurnGameManager.turnDidStart() to allow the manager to perform any post-start turn processing. This assumes that a valid turn holder has been assigned. If some pre-game preparation needs to take place in a non-turn-based manner, this function should not be called until it is time to start the first turn.

Overrides:
startTurn in class TurnGameManagerDelegate

endTurn

public void endTurn()
Description copied from class: TurnGameManagerDelegate
Called to end the turn. Whatever indication a game manager has that the turn has ended (probably the submission of a valid move of some sort by the turn holding player), it should call this function to cause this turn to end and the next to begin.

If the game is no longer in play (see TurnGameObject.isInPlay()) after having called TurnGameManager.turnDidEnd() and TurnGameManagerDelegate.setNextTurnHolder(), then the next turn will not automatically be started.

If the game is in play, but the next turn should not be started immediately, the game manager should have TurnGameManagerDelegate.setNextTurnHolder() set the TurnGameManagerDelegate._turnIdx field to -1 which will cause us to not start the next turn. To start things back up again it would set TurnGameManagerDelegate._turnIdx to the next turn holder and call TurnGameManagerDelegate.startTurn() itself.

Overrides:
endTurn in class TurnGameManagerDelegate

startHand

public void startHand()
Starts a hand of cards. Calls handWillStart(), sets the trick state to PLAYING_HAND, and calls handDidStart().


endHand

public void endHand()
Ends the hand of cards. Calls handWillEnd(), sets the trick state to BETWEEN_HANDS, and calls handDidEnd().


startTrick

public void startTrick()
Starts a trick. Calls trickWillStart(), sets the trick state to PLAYING_TRICK, and calls trickDidStart().


endTrick

public void endTrick()
Ends the trick. Calls trickWillEnd(), sets the trick state to PLAYING_HAND, and calls trickDidEnd().


sendCardsToPlayer

public void sendCardsToPlayer(ClientObject client,
                              int toidx,
                              Card[] cards)
Description copied from interface: TrickCardGameProvider
Handles a TrickCardGameService.sendCardsToPlayer(int, com.threerings.parlor.card.data.Card[]) request.

Specified by:
sendCardsToPlayer in interface TrickCardGameProvider

playCard

public void playCard(ClientObject client,
                     Card card,
                     int handSize)
Description copied from interface: TrickCardGameProvider
Handles a TrickCardGameService.playCard(com.threerings.parlor.card.data.Card, int) request.

Specified by:
playCard in interface TrickCardGameProvider

requestRematch

public void requestRematch(ClientObject client)
Description copied from interface: TrickCardGameProvider
Handles a TrickCardGameService.requestRematch() request.

Specified by:
requestRematch in interface TrickCardGameProvider

sendCardsToPlayer

protected void sendCardsToPlayer(int fromidx,
                                 int toidx,
                                 Card[] cards)
Sends cards between players without error checking. Default implementation transfers the cards between hands and notifies everyone of the transfer using CardGameManager.transferCardsBetweenPlayers(int, int, Card[]).


playCard

protected void playCard(int pidx,
                        Card card)
Plays a card for a player without error checking.


getRematchRequestCount

protected int getRematchRequestCount()
Returns the number of players currently requesting or accepting a rematch.


isTrickComplete

protected boolean isTrickComplete()
Checks whether the trick is complete--that is, whether each player has played a card.


setFirstTurnHolder

protected void setFirstTurnHolder()
Description copied from class: TurnGameManagerDelegate
This is called to determine which player will take the first turn. The default implementation chooses a player at random.

Overrides:
setFirstTurnHolder in class TurnGameManagerDelegate

setNextTurnHolder

protected void setNextTurnHolder()
Description copied from class: TurnGameManagerDelegate
This is called to determine which player will next hold the turn. The default implementation simply rotates through the players in order, but some games may need to mess with the turn from time to time. This should update the _turnIdx field, not set the turn holder field in the game object directly.

Overrides:
setNextTurnHolder in class TurnGameManagerDelegate

turnTimedOut

protected void turnTimedOut()
Called when the current turn times out. Default implementation plays a random playable card if in the trick-playing state.


reduceTurnDurationScale

protected void reduceTurnDurationScale(int pidx)
Reduces the specified player's turn duration due to a time-out.


increaseTurnDurationScale

protected void increaseTurnDurationScale(int pidx)
Increases the specified player's turn duration due to avoiding a time-out.


pickRandomPlayableCard

protected Card pickRandomPlayableCard(Hand hand)
Returns a random playable card from the specified hand.


handWillStart

protected void handWillStart()
Notifies the object that a new hand is about to start.


handDidStart

protected void handDidStart()
Notifies the object that a new hand has just started. Default implementation prepares the deck, deals the hands, and starts the first trick.


prepareDeck

protected void prepareDeck()
Prepares the deck for a new hand of cards. Default implementation resets to a full deck without jokers and shuffles.


dealHands

protected void dealHands()
Deals hands to the players. Default implementation deals the entire deck to the players in equal-sized hands.


handWillEnd

protected void handWillEnd()
Notifies the object that the hand is about to end.


handDidEnd

protected void handDidEnd()
Notifies the object that the hand has ended. Default implementation starts the next hand.


trickWillStart

protected void trickWillStart()
Notifies the object that a new trick is about to start. Default implementation resets the array of cards played.


trickDidStart

protected void trickDidStart()
Notifies the object that a new trick has started. Default implementation sets the first turn holder and starts the turn.


trickWillEnd

protected void trickWillEnd()
Notifies the object that the trick is about to end.


trickDidEnd

protected void trickDidEnd()
Notifies the object that the trick has ended. Default implementation records the last cards played and starts the next trick, unless a player has run out of cards, in which case it ends the hand.


anyHandsEmpty

protected boolean anyHandsEmpty()
Checks whether any hands are empty.