com.threerings.parlor.turn.server
Class TurnGameManagerDelegate

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
Direct Known Subclasses:
TrickCardGameManagerDelegate

public class TurnGameManagerDelegate
extends GameManagerDelegate

Performs the server-side turn-based game processing for a turn based game. Game managers which wish to make use of the turn services must implement TurnGameManager and either create an instance of this class, or an instance of a derivation which customizes the behavior, either of which would be passed to PlaceManager.addDelegate(com.threerings.crowd.server.PlaceManagerDelegate) to be activated.


Field Summary
protected  TurnGameManager _tgmgr
          The game manager for which we are delegating.
protected  TurnGameObject _turnGame
          A reference to our game object.
protected  int _turnIdx
          The player index of the current turn holder or -1 if it's no one's turn.
 
Fields inherited from class com.threerings.parlor.server.PlayManagerDelegate
_gmgr
 
Fields inherited from class com.threerings.crowd.server.PlaceManagerDelegate
_invmgr, _omgr, _plmgr
 
Constructor Summary
TurnGameManagerDelegate()
           
TurnGameManagerDelegate(TurnGameManager tgmgr)
          Deprecated. use the zero-argument constructor.
 
Method Summary
protected  void assignTurnRandomly()
          Convenience function to randomly assign the turn.
 void didInit(PlaceConfig config)
           
 void didStartup(PlaceObject plobj)
           
 void endTurn()
          Called to end the turn.
 void gameDidStart()
          This should be called from GameManager.gameDidStart() to let the turn delegate perform start of game processing.
 int getTurnHolderIndex()
          Returns the index of the current turn holder as configured in the game object.
 boolean isPlayersTurn(int playerIndex)
          Test if it's the inputted player's turn.
 void playerWasReplaced(int pidx, Name oplayer, Name nplayer)
          Called when a player in the game has been replaced by a call to GameManager.replacePlayer(int, com.threerings.util.Name).
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 startTurn()
          Called to start the next turn.
 
Methods inherited from class com.threerings.parlor.game.server.GameManagerDelegate
gameDidEnd, gameWillEnd, gameWillReset, gameWillStart, 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, init, placeBecameEmpty, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tgmgr

protected TurnGameManager _tgmgr
The game manager for which we are delegating.


_turnGame

protected TurnGameObject _turnGame
A reference to our game object.


_turnIdx

protected int _turnIdx
The player index of the current turn holder or -1 if it's no one's turn.

Constructor Detail

TurnGameManagerDelegate

public TurnGameManagerDelegate()

TurnGameManagerDelegate

@Deprecated
public TurnGameManagerDelegate(TurnGameManager tgmgr)
Deprecated. use the zero-argument constructor.

Method Detail

getTurnHolderIndex

public int getTurnHolderIndex()
Returns the index of the current turn holder as configured in the game object.

Returns:
the index into the players array of the current turn holder or -1 if there is no current turn holder.

isPlayersTurn

public boolean isPlayersTurn(int playerIndex)
Test if it's the inputted player's turn.


startTurn

public void startTurn()
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.


endTurn

public void endTurn()
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 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 setNextTurnHolder() set the _turnIdx field to -1 which will cause us to not start the next turn. To start things back up again it would set _turnIdx to the next turn holder and call startTurn() itself.


didInit

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

didStartup

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

playerWasReplaced

public void playerWasReplaced(int pidx,
                              Name oplayer,
                              Name nplayer)
Description copied from class: GameManagerDelegate
Called when a player in the game has been replaced by a call to GameManager.replacePlayer(int, com.threerings.util.Name).

Overrides:
playerWasReplaced in class GameManagerDelegate

gameDidStart

public void gameDidStart()
This should be called from GameManager.gameDidStart() to let the turn delegate perform start of game processing.

Overrides:
gameDidStart in class GameManagerDelegate

setFirstTurnHolder

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


setNextTurnHolder

protected void setNextTurnHolder()
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.


assignTurnRandomly

protected void assignTurnRandomly()
Convenience function to randomly assign the turn.