diff --git a/src/java/com/threerings/parlor/game/GameManager.java b/src/java/com/threerings/parlor/game/GameManager.java index 153ffea7e..476a9bade 100644 --- a/src/java/com/threerings/parlor/game/GameManager.java +++ b/src/java/com/threerings/parlor/game/GameManager.java @@ -1,5 +1,5 @@ // -// $Id: GameManager.java,v 1.51 2002/10/24 19:05:46 mdb Exp $ +// $Id: GameManager.java,v 1.52 2002/10/27 23:54:32 shaper Exp $ package com.threerings.parlor.game; @@ -484,7 +484,8 @@ public class GameManager extends PlaceManager * Called when the game is about to start, but before the game start * notification has been delivered to the players. Derived classes * should override this if they need to perform some pre-start - * activities. + * activities, but should be sure to call + * super.gameWillStart(). */ protected void gameWillStart () { @@ -503,7 +504,8 @@ public class GameManager extends PlaceManager * Called after the game start notification was dispatched. Derived * classes can override this to put whatever wheels they might need * into motion now that the game is started (if anything other than - * transitioning the game to {@link GameObject#IN_PLAY} is necessary). + * transitioning the game to {@link GameObject#IN_PLAY} is necessary), + * but should be sure to call super.gameDidStart(). */ protected void gameDidStart () { @@ -565,10 +567,23 @@ public class GameManager extends PlaceManager return; } - // figure out who won... + try { + _gameobj.startTransaction(); - // transition to the game over state - _gameobj.setState(GameObject.GAME_OVER); + // let the derived class do its pre-end stuff + gameWillEnd(); + + // determine winners and set them in the game object + boolean[] winners = new boolean[getPlayerSlots()]; + assignWinners(winners); + _gameobj.setWinners(winners); + + // transition to the game over state + _gameobj.setState(GameObject.GAME_OVER); + + } finally { + _gameobj.commitTransaction(); + } // wait until we hear the game state transition on the game object // to invoke our game over code so that we can be sure that any @@ -576,10 +591,40 @@ public class GameManager extends PlaceManager // endGame() have been dispatched } + /** + * Assigns the final winning status for each player to their respect + * player index in the supplied array. This will be called by {@link + * #endGame} when the game is over. The default implementation marks + * no players as winners. Derived classes should override this method + * in order to customize the winning conditions. + */ + protected void assignWinners (boolean[] winners) + { + Arrays.fill(winners, false); + } + + /** + * Called when the game is about to end, but before the game end + * notification has been delivered to the players. Derived classes + * should override this if they need to perform some pre-end + * activities, but should be sure to call + * super.gameWillEnd(). + */ + protected void gameWillEnd () + { + // let our delegates do their business + applyToDelegates(new DelegateOp() { + public void apply (PlaceManagerDelegate delegate) { + ((GameManagerDelegate)delegate).gameWillEnd(); + } + }); + } + /** * Called after the game has transitioned to the {@link * GameObject#GAME_OVER} state. Derived classes should override this - * to perform any post-game activities. + * to perform any post-game activities, but should be sure to call + * super.gameDidEnd(). */ protected void gameDidEnd () { @@ -641,7 +686,8 @@ public class GameManager extends PlaceManager /** * Called after the game has been reset. Derived classes can override * this to put whatever wheels they might need into motion now that - * the game is reset. + * the game is reset, but should be sure to call + * super.gameDidReset(). */ protected void gameDidReset () { diff --git a/src/java/com/threerings/parlor/game/GameManagerDelegate.java b/src/java/com/threerings/parlor/game/GameManagerDelegate.java index 42fb7924d..5f21a51e6 100644 --- a/src/java/com/threerings/parlor/game/GameManagerDelegate.java +++ b/src/java/com/threerings/parlor/game/GameManagerDelegate.java @@ -1,5 +1,5 @@ // -// $Id: GameManagerDelegate.java,v 1.5 2002/06/19 23:41:25 shaper Exp $ +// $Id: GameManagerDelegate.java,v 1.6 2002/10/27 23:54:32 shaper Exp $ package com.threerings.parlor.game; @@ -45,6 +45,13 @@ public class GameManagerDelegate extends PlaceManagerDelegate { } + /** + * Called by the game manager when the game is about to end. + */ + public void gameWillEnd () + { + } + /** * Called by the game manager after the game ended. */ diff --git a/src/java/com/threerings/parlor/game/GameObject.dobj b/src/java/com/threerings/parlor/game/GameObject.dobj index 5327768f7..2e331e57b 100644 --- a/src/java/com/threerings/parlor/game/GameObject.dobj +++ b/src/java/com/threerings/parlor/game/GameObject.dobj @@ -1,5 +1,5 @@ // -// $Id: GameObject.dobj,v 1.16 2002/10/16 00:19:23 shaper Exp $ +// $Id: GameObject.dobj,v 1.17 2002/10/27 23:54:32 shaper Exp $ package com.threerings.parlor.game; @@ -46,6 +46,10 @@ public class GameObject extends PlaceObject /** The usernames of the players involved in this game. */ public String[] players; + /** Whether each player in the game is a winner, or null + * if the game is not yet over. */ + public boolean[] winners; + /** The unique round identifier for the current round. */ public int roundId; diff --git a/src/java/com/threerings/parlor/game/GameObject.java b/src/java/com/threerings/parlor/game/GameObject.java index a5310f153..e8692086b 100644 --- a/src/java/com/threerings/parlor/game/GameObject.java +++ b/src/java/com/threerings/parlor/game/GameObject.java @@ -1,5 +1,5 @@ // -// $Id: GameObject.java,v 1.11 2002/10/16 00:19:23 shaper Exp $ +// $Id: GameObject.java,v 1.12 2002/10/27 23:54:32 shaper Exp $ package com.threerings.parlor.game; @@ -32,6 +32,9 @@ public class GameObject extends PlaceObject /** The field name of the players field. */ public static final String PLAYERS = "players"; + /** The field name of the winners field. */ + public static final String WINNERS = "winners"; + /** The field name of the roundId field. */ public static final String ROUND_ID = "roundId"; @@ -64,6 +67,10 @@ public class GameObject extends PlaceObject /** The usernames of the players involved in this game. */ public String[] players; + /** Whether each player in the game is a winner, or null + * if the game is not yet over. */ + public boolean[] winners; + /** The unique round identifier for the current round. */ public int roundId; @@ -187,6 +194,34 @@ public class GameObject extends PlaceObject requestElementUpdate(PLAYERS, value, index); } + /** + * Requests that the winners field be set to the specified + * value. The local value will be updated immediately and an event + * will be propagated through the system to notify all listeners that + * the attribute did change. Proxied copies of this object (on + * clients) will apply the value change when they received the + * attribute changed notification. + */ + public void setWinners (boolean[] winners) + { + this.winners = winners; + requestAttributeChange(WINNERS, winners); + } + + /** + * Requests that the indexth element of + * winners field be set to the specified value. The local + * value will be updated immediately and an event will be propagated + * through the system to notify all listeners that the attribute did + * change. Proxied copies of this object (on clients) will apply the + * value change when they received the attribute changed notification. + */ + public void setWinnersAt (boolean value, int index) + { + this.winners[index] = value; + requestElementUpdate(WINNERS, new Boolean(value), index); + } + /** * Requests that the roundId field be set to the specified * value. The local value will be updated immediately and an event