diff --git a/src/java/com/threerings/ezgame/server/EZGameManager.java b/src/java/com/threerings/ezgame/server/EZGameManager.java index 8f4f8ce7..9debfb8f 100644 --- a/src/java/com/threerings/ezgame/server/EZGameManager.java +++ b/src/java/com/threerings/ezgame/server/EZGameManager.java @@ -73,7 +73,7 @@ public class EZGameManager extends GameManager { public EZGameManager () { - addDelegate(_turnDelegate = new EZGameTurnDelegate(this)); + addDelegate(_turnDelegate = new EZGameTurnDelegate()); } /** diff --git a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java index 8d9bd57e..33d916f4 100644 --- a/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java +++ b/src/java/com/threerings/ezgame/server/EZGameTurnDelegate.java @@ -33,11 +33,6 @@ import com.threerings.parlor.turn.server.TurnGameManagerDelegate; */ public class EZGameTurnDelegate extends TurnGameManagerDelegate { - public EZGameTurnDelegate (EZGameManager mgr) - { - super(mgr); - } - /** * A form of endTurn where you can specify the next turn holder oid. */ diff --git a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java index a3dcf79e..ae006b96 100644 --- a/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/card/trick/server/TrickCardGameManagerDelegate.java @@ -37,7 +37,8 @@ import com.threerings.presents.server.PresentsServer; import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.PlaceObject; -import com.threerings.parlor.game.server.GameManager; +import com.threerings.crowd.server.PlaceManager; + import com.threerings.parlor.turn.server.TurnGameManagerDelegate; import com.threerings.parlor.card.Log; @@ -55,112 +56,116 @@ import com.threerings.parlor.card.trick.data.TrickCardGameObject; */ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate implements TrickCardGameProvider -{ - /** - * Constructor. - * - * @param manager the game manager - */ - public TrickCardGameManagerDelegate (CardGameManager manager) +{ + public TrickCardGameManagerDelegate () { - super(manager); - - _cgmgr = manager; - _deck = new Deck(); } - - // Documentation inherited. + + /** + * @deprecated use the zero-argument constructor. + */ + @Deprecated public TrickCardGameManagerDelegate (CardGameManager manager) + { + } + + @Override // from PlaceManagerDelegate + public void setPlaceManager (PlaceManager plmgr) + { + super.setPlaceManager(plmgr); + _cgmgr = (CardGameManager)plmgr; + } + + @Override // from PlaceManagerDelegate public void didStartup (PlaceObject plobj) { super.didStartup(plobj); - + + _deck = new Deck(); _trickCardGame = (TrickCardGameObject)plobj; - _cardGame = (CardGameObject)plobj; - _trickCardGame.setTrickCardGameService( (TrickCardGameMarshaller)PresentsServer.invmgr.registerDispatcher( new TrickCardGameDispatcher(this))); } - - // Documentation inherited. + + @Override // from PlaceManagerDelegate public void didShutdown () { super.didShutdown(); - + PresentsServer.invmgr.clearDispatcher(_trickCardGame.getTrickCardGameService()); } - - // Documentation inherited. + + @Override // from GameManagerDelegate public void gameWillStart () { super.gameWillStart(); - + // clear out the last cards played _trickCardGame.setLastCardsPlayed(null); - + // initialize the turn duration scales float[] scales = new float[_cardGame.getPlayerCount()]; Arrays.fill(scales, 1.0f); _trickCardGame.setTurnDurationScales(scales); } - + /** * Called when the game has started. Default implementation starts the first hand. */ public void gameDidStart () { super.gameDidStart(); - + // start the first hand startHand(); } - - // Documentation inherited. + + @Override // from GameManagerDelegate public void gameDidEnd () { super.gameDidEnd(); - + // make sure all intervals are cancelled _turnTimeoutInterval.cancel(); _endTrickInterval.cancel(); - + // make sure trick state is back to between hands if (_trickCardGame.getTrickState() != TrickCardGameObject.BETWEEN_HANDS) { _trickCardGame.setTrickState(TrickCardGameObject.BETWEEN_HANDS); } - + // initialize the array of rematch requests - _trickCardGame.setRematchRequests(new int[_cardGame.getPlayerCount()]); + _trickCardGame.setRematchRequests(new int[_cardGame.getPlayerCount()]); } - - // Documentation inherited. + + @Override // from TurnGameManagerDelegate public void startTurn () { super.startTurn(); - + // initialize the timeout flag and schedule the timeout interval _turnTimedOut = false; _turnTimeoutInterval.schedule(_trickCardGame.getTurnDuration()); } - - // Documentation inherited. + + @Override // from TurnGameManagerDelegate public void endTurn () { // cancel the timeout interval _turnTimeoutInterval.cancel(); - + // reduce or increase the turn duration scale if (_turnTimedOut) { reduceTurnDurationScale(_turnIdx); - + } else { increaseTurnDurationScale(_turnIdx); } - + super.endTurn(); } - + /** * Starts a hand of cards. Calls {@link #handWillStart}, sets the trick * state to PLAYING_HAND, and calls {@link #handDidStart}. @@ -171,7 +176,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTrickState(TrickCardGameObject.PLAYING_HAND); handDidStart(); } - + /** * Ends the hand of cards. Calls {@link #handWillEnd}, sets the trick * state to BETWEEN_HANDS, and calls {@link #handDidEnd}. @@ -182,7 +187,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTrickState(TrickCardGameObject.BETWEEN_HANDS); handDidEnd(); } - + /** * Starts a trick. Calls {@link #trickWillStart}, sets the trick * state to PLAYING_TRICK, and calls {@link #trickDidStart}. @@ -193,7 +198,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTrickState(TrickCardGameObject.PLAYING_TRICK); trickDidStart(); } - + /** * Ends the trick. Calls {@link #trickWillEnd}, sets the trick * state to PLAYING_HAND, and calls {@link #trickDidEnd}. @@ -204,12 +209,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTrickState(TrickCardGameObject.PLAYING_HAND); trickDidEnd(); } - - /** - * Processes a request to transfer a group of cards between players. - * Default implementation verifies that the user's hand contains the - * specified cards, then calls {@link #sendCardsToPlayer(int, int, Card[])}. - */ + + // from interface TrickCardGameProvider public void sendCardsToPlayer (ClientObject client, int toidx, Card[] cards) { // make sure they're actually a player @@ -219,18 +220,91 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate ((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "]."); return; } - + // make sure they have the cards if (!_hands[fromidx].containsAll(cards)) { Log.warning("Tried to send cards not held [username=" + ((BodyObject)client).who() + ", cards=" + StringUtil.toString(cards) + "]."); return; } - + // send the cards sendCardsToPlayer(fromidx, toidx, cards); } - + + // from interface TrickCardGameProvider + public void playCard (ClientObject client, Card card, int handSize) + { + // make sure we're playing a trick + if (_trickCardGame.getTrickState() != TrickCardGameObject.PLAYING_TRICK) { + return; // silently ignore play attempts after timeouts + } + + // make sure it's their turn + Name username = ((BodyObject)client).getVisibleName(); + if (!username.equals(_trickCardGame.getTurnHolder())) { + return; + } + + // make sure they're on the right trick + int pidx = _cardGame.getPlayerIndex(username); + if (_hands[pidx].size() != handSize) { + return; + } + + // make sure their hand contains the specified card + if (!_hands[pidx].contains(card)) { + Log.warning("Tried to play card not held [username=" + username + + ", card=" + card + "]."); + return; + } + + // make sure the card is legal to play + if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) { + Log.warning("Tried to play illegal card [username=" + username + + ", card=" + card + "]."); + return; + } + + // play the card + playCard(pidx, card); + } + // from interface TrickCardGameProvider + public void requestRematch (ClientObject client) + { + // make sure the game is over + if (_cardGame.state != CardGameObject.GAME_OVER) { + Log.warning("Tried to request rematch when game wasn't over " + + "[username=" + ((BodyObject)client).who() + "]."); + return; + } + + // make sure the requester is one of the players + int pidx = _cgmgr.getPlayerIndex(client); + if (pidx == -1) { + Log.warning("Rematch request from non-player [username=" + + ((BodyObject)client).who() + "]."); + return; + } + + // make sure the player hasn't already requested + if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) { + Log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "]."); + return; + } + + // if player is first requesting, set to request; else set to accept + int req = (getRematchRequestCount() == 0 ? + TrickCardGameObject.REQUESTS_REMATCH : + TrickCardGameObject.ACCEPTS_REMATCH); + _trickCardGame.setRematchRequestsAt(req, pidx); + + // if all players accept the rematch, restart the game + if (getRematchRequestCount() == _cardGame.getPlayerCount()) { + _cgmgr.rematchGame(); + } + } + /** * Sends cards between players without error checking. Default * implementation transfers the cards between hands and notifies @@ -241,52 +315,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { // remove from sending player's hand _hands[fromidx].removeAll(cards); - + // add to receiving player's hand _hands[toidx].addAll(cards); - + // notify everyone of the transfer _cgmgr.transferCardsBetweenPlayers(fromidx, toidx, cards); } - - // Documentation inherited. - public void playCard (ClientObject client, Card card, int handSize) - { - // make sure we're playing a trick - if (_trickCardGame.getTrickState() != TrickCardGameObject.PLAYING_TRICK) { - return; // silently ignore play attempts after timeouts - } - - // make sure it's their turn - Name username = ((BodyObject)client).getVisibleName(); - if (!username.equals(_trickCardGame.getTurnHolder())) { - return; - } - - // make sure they're on the right trick - int pidx = _cardGame.getPlayerIndex(username); - if (_hands[pidx].size() != handSize) { - return; - } - - // make sure their hand contains the specified card - if (!_hands[pidx].contains(card)) { - Log.warning("Tried to play card not held [username=" + username + - ", card=" + card + "]."); - return; - } - - // make sure the card is legal to play - if (!_trickCardGame.isCardPlayable(_hands[pidx], card)) { - Log.warning("Tried to play illegal card [username=" + username + - ", card=" + card + "]."); - return; - } - - // play the card - playCard(pidx, card); - } - + /** * Plays a card for a player without error checking. */ @@ -300,15 +336,15 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate PlayerCard[] cards = (PlayerCard[])ArrayUtil.append( _trickCardGame.getCardsPlayed(), new PlayerCard(pidx, card)); _trickCardGame.setCardsPlayed(cards); - + // end the user's turn endTurn(); - + // end the trick if everyone has played a card if (_turnIdx == -1) { if (_endTrickDelay == 0) { endTrick(); - + } else { _endTrickInterval.schedule(_endTrickDelay); } @@ -317,43 +353,8 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate ((DObject) _trickCardGame).commitTransaction(); } } - - // Documentation inherited. - public void requestRematch (ClientObject client) - { - // make sure the game is over - if (_cardGame.state != CardGameObject.GAME_OVER) { - Log.warning("Tried to request rematch when game wasn't over " + - "[username=" + ((BodyObject)client).who() + "]."); - return; - } - - // make sure the requester is one of the players - int pidx = _cgmgr.getPlayerIndex(client); - if (pidx == -1) { - Log.warning("Rematch request from non-player [username=" + - ((BodyObject)client).who() + "]."); - return; - } - - // make sure the player hasn't already requested - if (_trickCardGame.getRematchRequests()[pidx] != TrickCardGameObject.NO_REQUEST) { - Log.warning("Repeated rematch request [username=" + ((BodyObject)client).who() + "]."); - return; - } - - // if player is first requesting, set to request; else set to accept - int req = (getRematchRequestCount() == 0 ? - TrickCardGameObject.REQUESTS_REMATCH : - TrickCardGameObject.ACCEPTS_REMATCH); - _trickCardGame.setRematchRequestsAt(req, pidx); - - // if all players accept the rematch, restart the game - if (getRematchRequestCount() == _cardGame.getPlayerCount()) { - _cgmgr.rematchGame(); - } - } - + + /** * Returns the number of players currently requesting or accepting a rematch. */ @@ -368,7 +369,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate } return count; } - + /** * Checks whether the trick is complete--that is, whether each player has played a card. */ @@ -376,30 +377,30 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { return _trickCardGame.getCardsPlayed().length == _cardGame.getPlayerCount(); } - - // Documentation inherited. + + @Override // from TurnGameManagerDelegate protected void setFirstTurnHolder () { if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK) { super.setFirstTurnHolder(); - + } else { _turnIdx = -1; } } - - // Documentation inherited. + + @Override // from TurnGameManagerDelegate protected void setNextTurnHolder () { if (_trickCardGame.getTrickState() == TrickCardGameObject.PLAYING_TRICK && !isTrickComplete()) { super.setNextTurnHolder(); - + } else { _turnIdx = -1; } } - + /** * Called when the current turn times out. Default implementation * plays a random playable card if in the trick-playing state. @@ -410,7 +411,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate playCard(_turnIdx, pickRandomPlayableCard(_hands[_turnIdx])); } } - + /** * Reduces the specified player's turn duration due to a time-out. */ @@ -423,7 +424,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTurnDurationScalesAt(newScale, pidx); } } - + /** * Increases the specified player's turn duration due to avoiding a time-out. */ @@ -435,7 +436,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _trickCardGame.setTurnDurationScalesAt(newScale, pidx); } } - + /** * Returns a random playable card from the specified hand. */ @@ -450,13 +451,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate } return (Card)RandomUtil.pickRandom(playableCards); } - + /** * Notifies the object that a new hand is about to start. */ protected void handWillStart () - {} - + { + } + /** * Notifies the object that a new hand has just started. Default * implementation prepares the deck, deals the hands, and starts the first trick. @@ -465,14 +467,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { // prepare the deck prepareDeck(); - + // deal cards to players dealHands(); - + // start the first trick startTrick(); } - + /** * Prepares the deck for a new hand of cards. Default implementation * resets to a full deck without jokers and shuffles. @@ -482,7 +484,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate _deck.reset(false); _deck.shuffle(); } - + /** * Deals hands to the players. Default implementation deals the entire * deck to the players in equal-sized hands. @@ -491,13 +493,13 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { _hands = _cgmgr.dealHands(_deck, _deck.size() / _cardGame.getPlayerCount()); } - + /** * Notifies the object that the hand is about to end. */ protected void handWillEnd () {} - + /** * Notifies the object that the hand has ended. Default implementation * starts the next hand. @@ -506,7 +508,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { startHand(); } - + /** * Notifies the object that a new trick is about to start. Default * implementation resets the array of cards played. @@ -515,7 +517,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { _trickCardGame.setCardsPlayed(new PlayerCard[0]); } - + /** * Notifies the object that a new trick has started. Default * implementation sets the first turn holder and starts the turn. @@ -525,13 +527,14 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate setFirstTurnHolder(); startTurn(); } - + /** * Notifies the object that the trick is about to end. */ protected void trickWillEnd () - {} - + { + } + /** * Notifies the object that the trick has ended. Default implementation * records the last cards played and starts the next trick, unless a @@ -541,20 +544,20 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate { // store the trick results for late-joiners _trickCardGame.setLastCardsPlayed(_trickCardGame.getCardsPlayed()); - + // clear out the cards played in the trick _trickCardGame.setCardsPlayed(null); - + // verify that each player has at least one card if (anyHandsEmpty()) { endHand(); return; } - + // everyone has cards; let's play another trick startTrick(); } - + /** * Checks whether any hands are empty. */ @@ -567,28 +570,7 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate } return false; } - - /** The card game manager. */ - protected CardGameManager _cgmgr; - - /** The game object as trick card game. */ - protected TrickCardGameObject _trickCardGame; - - /** The game object as card game. */ - protected CardGameObject _cardGame; - - /** The amount of time to wait before ending the trick. */ - protected long _endTrickDelay; - - /** The deck from which cards are dealt. */ - protected Deck _deck; - - /** The hands of each player. */ - protected Hand[] _hands; - - /** Whether or not the turn timed out. */ - protected boolean _turnTimedOut; - + /** The all-purpose turn timeout interval. */ protected Interval _turnTimeoutInterval = new Interval(PresentsServer.omgr) { public void expired () { @@ -596,22 +578,41 @@ public class TrickCardGameManagerDelegate extends TurnGameManagerDelegate turnTimedOut(); } }; - + /** Calls {@link #endTrick} upon expiration. */ protected Interval _endTrickInterval = new Interval(PresentsServer.omgr) { public void expired () { endTrick(); } }; - + + /** The card game manager. */ + protected CardGameManager _cgmgr; + + /** The game object as trick card game. */ + protected TrickCardGameObject _trickCardGame; + + /** The game object as card game. */ + protected CardGameObject _cardGame; + + /** The amount of time to wait before ending the trick. */ + protected long _endTrickDelay; + + /** The deck from which cards are dealt. */ + protected Deck _deck; + + /** The hands of each player. */ + protected Hand[] _hands; + + /** Whether or not the turn timed out. */ + protected boolean _turnTimedOut; + /** Reduce turn duration scales by this amount each time the player times out. */ protected static final float TURN_DURATION_SCALE_REDUCTION = 0.25f; - - /** - * Increase turn duration scales by this amount each time the player - * manages not to time out. */ + + /** Turn duration scales increase by this amount each time the player doesn't time out. */ protected static final float TURN_DURATION_SCALE_INCREASE = 0.5f; - + /** Don't let turn duration scales get below this level. */ protected static final float MINIMUM_TURN_DURATION_SCALE = 0.1f; } diff --git a/src/java/com/threerings/parlor/game/server/GameManagerDelegate.java b/src/java/com/threerings/parlor/game/server/GameManagerDelegate.java index 1e6668aa..cb8903d1 100644 --- a/src/java/com/threerings/parlor/game/server/GameManagerDelegate.java +++ b/src/java/com/threerings/parlor/game/server/GameManagerDelegate.java @@ -28,18 +28,19 @@ import com.threerings.crowd.server.PlaceManagerDelegate; import com.threerings.parlor.game.data.GameAI; /** - * Extends the {@link PlaceManagerDelegate} mechanism with game manager - * specific methods. + * Extends the {@link PlaceManagerDelegate} mechanism with game manager specific methods. */ public class GameManagerDelegate extends PlaceManagerDelegate { - /** - * Provides the delegate with a reference to the game manager for - * which it is delegating. - */ - public GameManagerDelegate (GameManager gmgr) + public GameManagerDelegate () + { + } + + /** + * @deprecated use the zero-argument constructor. + */ + @Deprecated public GameManagerDelegate (GameManager gmgr) { - super(gmgr); } /** @@ -57,16 +58,15 @@ public class GameManagerDelegate extends PlaceManagerDelegate } /** - * Called when a player in the game has been replaced by a call to - * {@link GameManager#replacePlayer}. + * Called when a player in the game has been replaced by a call to {@link + * GameManager#replacePlayer}. */ public void playerWasReplaced (int pidx, Name oldPlayer, Name newPlayer) { } /** - * Called by the manager when we should do some AI. Only called while - * the game is IN_PLAY. + * Called by the manager when we should do some AI. Only called while the game is IN_PLAY. * * @param pidx the player index to fake some gameplay for. * @param ai a record indicating the AI's configuration. @@ -90,17 +90,16 @@ public class GameManagerDelegate extends PlaceManagerDelegate } /** - * Called when the game is about to reset, but before any other - * clearing out of game data has taken place. Derived classes should - * override this if they need to perform some pre-reset activities. + * Called when the game is about to reset, but before any other clearing out of game data has + * taken place. Derived classes should override this if they need to perform some pre-reset + * activities. */ public void gameWillReset () { } /** - * Called when the specified player has been set as an AI with the - * supplied AI configuration. + * Called when the specified player has been set as an AI with the supplied AI configuration. */ public void setAI (int pidx, GameAI ai) { diff --git a/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java b/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java index e0bbae22..39a2288e 100644 --- a/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java +++ b/src/java/com/threerings/parlor/rating/server/RatingManagerDelegate.java @@ -42,8 +42,10 @@ import com.threerings.util.Name; import com.threerings.media.util.MathUtil; import com.threerings.crowd.data.BodyObject; +import com.threerings.crowd.data.PlaceConfig; import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.server.CrowdServer; +import com.threerings.crowd.server.PlaceManager; import com.threerings.parlor.game.data.GameConfig; import com.threerings.parlor.game.data.GameObject; @@ -60,13 +62,17 @@ import com.threerings.parlor.rating.server.persist.RatingRepository; public abstract class RatingManagerDelegate extends GameManagerDelegate implements RatingCodes { - /** - * Constructs a rating manager delegate. - */ - public RatingManagerDelegate (GameManager gmgr) + @Override // from PlaceManagerDelegate + public void setPlaceManager (PlaceManager plmgr) { - super(gmgr); - _gmgr = gmgr; + super.setPlaceManager(plmgr); + _gmgr = (GameManager)plmgr; + } + + @Override // from PlaceManagerDelegate + public void didInit (PlaceConfig config) + { + super.didInit(config); _repo = getRatingRepository(); } diff --git a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java index 920219f5..975cd4bf 100644 --- a/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java +++ b/src/java/com/threerings/parlor/turn/server/TurnGameManagerDelegate.java @@ -25,6 +25,7 @@ import com.samskivert.util.RandomUtil; import com.threerings.util.Name; import com.threerings.crowd.data.PlaceObject; +import com.threerings.crowd.server.PlaceManager; import com.threerings.parlor.Log; import com.threerings.parlor.game.server.GameManager; @@ -33,31 +34,36 @@ import com.threerings.parlor.game.server.GameManagerDelegate; import com.threerings.parlor.turn.data.TurnGameObject; /** - * 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 - * {@link 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 {@link GameManager#addDelegate} to be activated. + * 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 {@link 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 {@link GameManager#addDelegate} to be activated. */ public class TurnGameManagerDelegate extends GameManagerDelegate { - /** - * Constructs a delegate that will manage the turn game state and call back - * to the supplied {@link TurnGameManager} implementation to let it in on - * the progression of the game. - */ - public TurnGameManagerDelegate (TurnGameManager tgmgr) + public TurnGameManagerDelegate () { - super((GameManager)tgmgr); - _tgmgr = tgmgr; } /** - * Returns the index of the current turn holder as configured in the game - * object. + * @deprecated use the zero-argument constructor. + */ + @Deprecated public TurnGameManagerDelegate (TurnGameManager tgmgr) + { + } + + @Override // from PlaceManagerDelegate + public void setPlaceManager (PlaceManager plmgr) + { + super.setPlaceManager(plmgr); + _tgmgr = (TurnGameManager)plmgr; + } + + /** + * Returns the index of the current turn holder as configured in the game object. * - * @return the index into the players array of the current turn holder or - * -1 if there is no current turn holder. + * @return the index into the players array of the current turn holder or -1 if + * there is no current turn holder. */ public int getTurnHolderIndex () { @@ -67,8 +73,7 @@ public class TurnGameManagerDelegate extends GameManagerDelegate /** Test if it's the inputted player's turn. */ public boolean isPlayersTurn (int playerIndex) { - // Don't accidently match a visitor's id of -1 with the "no one's - // turn" state of turn -1. + // Don't accidently match a visitor's id of -1 with the "no one's turn" state of turn -1. int turnHolder = getTurnHolderIndex(); if (turnHolder < 0) { return false; @@ -79,22 +84,20 @@ public class TurnGameManagerDelegate extends GameManagerDelegate } /** - * Called to start the next turn. It calls {@link - * 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 {@link 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. + * Called to start the next turn. It calls {@link 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 + * {@link 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. */ public void startTurn () { // sanity check if (_turnIdx < 0 || _turnIdx >= _turnGame.getPlayers().length) { - Log.warning("startTurn() called with invalid turn index " + - "[game=" + where() + ", turnIdx=" + _turnIdx + "]."); + Log.warning("startTurn() called with invalid turn index [game=" + where() + + ", turnIdx=" + _turnIdx + "]."); // abort, abort return; } @@ -102,8 +105,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate // get the player name and sanity-check again Name name = _tgmgr.getPlayerName(_turnIdx); if (name == null) { - Log.warning("startTurn() called with invalid player " + - "[game=" + where() + ", turnIdx=" + _turnIdx + "]."); + Log.warning("startTurn() called with invalid player [game=" + where() + + ", turnIdx=" + _turnIdx + "]."); return; } @@ -118,21 +121,18 @@ public class TurnGameManagerDelegate extends GameManagerDelegate } /** - * 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. + * 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 {@link TurnGame#isInPlay}) - * after having called {@link TurnGameManager#turnDidEnd} and {@link - * #setNextTurnHolder}, then the next turn will not automatically be - * started. + *

If the game is no longer in play (see {@link TurnGame#isInPlay}) after having called + * {@link TurnGameManager#turnDidEnd} and {@link #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 {@link #setNextTurnHolder} set - * the {@link #_turnIdx} field to -1 which will cause us to - * not start the next turn. To start things back up again it would set - * {@link #_turnIdx} to the next turn holder and call {@link #startTurn} + *

If the game is in play, but the next turn should not be started immediately, the game + * manager should have {@link #setNextTurnHolder} set the {@link #_turnIdx} field to + * -1 which will cause us to not start the next turn. To start things back up + * again it would set {@link #_turnIdx} to the next turn holder and call {@link #startTurn} * itself. */ public void endTurn () @@ -162,20 +162,20 @@ public class TurnGameManagerDelegate extends GameManagerDelegate // documentation inherited public void playerWasReplaced (int pidx, Name oplayer, Name nplayer) { - // we need to update the turn holder if the current turn holder - // was the player that was replaced and we need to do so in a way - // that doesn't make everyone think that the turn just changed + // we need to update the turn holder if the current turn holder was the player that was + // replaced and we need to do so in a way that doesn't make everyone think that the turn + // just changed if (oplayer != null && oplayer.equals(_turnGame.getTurnHolder())) { - // small hackery: this will indicate to the client that we are - // replacing the turn holder rather than changing the turn + // small hackery: this will indicate to the client that we are replacing the turn + // holder rather than changing the turn _turnGame.setTurnHolder(TurnGameObject.TURN_HOLDER_REPLACED); _turnGame.setTurnHolder(nplayer); } } /** - * This should be called from {@link GameManager#gameDidStart} to let - * the turn delegate perform start of game processing. + * This should be called from {@link GameManager#gameDidStart} to let the turn delegate perform + * start of game processing. */ public void gameDidStart () { @@ -189,8 +189,8 @@ public class TurnGameManagerDelegate extends GameManagerDelegate } /** - * This is called to determine which player will take the first - * turn. The default implementation chooses a player at random. + * This is called to determine which player will take the first turn. The default + * implementation chooses a player at random. */ protected void setFirstTurnHolder () { @@ -198,10 +198,9 @@ public class TurnGameManagerDelegate extends GameManagerDelegate } /** - * 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 + * 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. */ protected void setNextTurnHolder () @@ -217,10 +216,10 @@ public class TurnGameManagerDelegate extends GameManagerDelegate do { _turnIdx = (_turnIdx + 1) % size; if (_turnIdx == oturnIdx) { - // if we've wrapped all the way around, stop where we are - // even if the current player is not active. - Log.warning("1 or less active players. Unable to properly " + - "change turn. [game=" + where() + "]."); + // if we've wrapped all the way around, stop where we are even if the current + // player is not active. + Log.warning("1 or less active players. Unable to properly change turn. " + + "[game=" + where() + "]."); break; } } while (!_tgmgr.isActivePlayer(_turnIdx)); @@ -251,7 +250,6 @@ public class TurnGameManagerDelegate extends GameManagerDelegate /** A reference to our game object. */ protected TurnGameObject _turnGame; - /** The player index of the current turn holder or -1 if - * it's no one's turn. */ + /** The player index of the current turn holder or -1 if it's no one's turn. */ protected int _turnIdx = -1; } diff --git a/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java b/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java index 84a2a857..17c1dd89 100644 --- a/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java +++ b/src/java/com/threerings/puzzle/drop/server/DropManagerDelegate.java @@ -64,14 +64,19 @@ public abstract class DropManagerDelegate extends PuzzleManagerDelegate implements PuzzleCodes, DropCodes { /** - * Provides the delegate with a reference to the manager for which it - * is delegating as well as the logic object that it uses to determine - * how to manage the drop puzzle. + * @deprecated use {@link #DropManagerDelegate(DropLogic)}. */ - public DropManagerDelegate (PuzzleManager puzmgr, DropLogic logic) + @Deprecated public DropManagerDelegate (PuzzleManager puzmgr, DropLogic logic) { - super(puzmgr); + this(logic); + } + /** + * Creates a drop manager delegate with a logic that it uses to determine how to manage the + * drop puzzle. + */ + public DropManagerDelegate (DropLogic logic) + { // configure the game-specific settings _usedrop = logic.useBlockDropping(); _userise = logic.useBoardRising(); diff --git a/src/java/com/threerings/puzzle/server/PuzzleManagerDelegate.java b/src/java/com/threerings/puzzle/server/PuzzleManagerDelegate.java index bf1432e4..8f227045 100644 --- a/src/java/com/threerings/puzzle/server/PuzzleManagerDelegate.java +++ b/src/java/com/threerings/puzzle/server/PuzzleManagerDelegate.java @@ -21,21 +21,31 @@ package com.threerings.puzzle.server; +import com.threerings.crowd.server.PlaceManager; import com.threerings.parlor.game.server.GameManagerDelegate; /** - * Extends the {@link GameManagerDelegate} mechanism with puzzle manager - * specific methods (of which there are currently none). + * Extends the {@link GameManagerDelegate} mechanism with puzzle manager specific methods (of which + * there are currently none). */ public class PuzzleManagerDelegate extends GameManagerDelegate { - /** - * Constructs a puzzle manager delegate. - */ - public PuzzleManagerDelegate (PuzzleManager puzmgr) + public PuzzleManagerDelegate () { - super(puzmgr); - _puzmgr = puzmgr; + } + + /** + * @deprecated use the zero-argument constructor. + */ + @Deprecated public PuzzleManagerDelegate (PuzzleManager puzmgr) + { + } + + @Override // from PlaceManagerDelegate + public void setPlaceManager (PlaceManager plmgr) + { + super.setPlaceManager(plmgr); + _puzmgr = (PuzzleManager)plmgr; } protected PuzzleManager _puzmgr;