Added gameWillEnd(), and GameObject.winners that details the winners of
the game, as assigned by GameManager.assignWinners() when the game ends. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1853 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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
|
||||
* <code>super.gameWillStart()</code>.
|
||||
*/
|
||||
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 <code>super.gameDidStart()</code>.
|
||||
*/
|
||||
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
|
||||
* <code>super.gameWillEnd()</code>.
|
||||
*/
|
||||
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
|
||||
* <code>super.gameDidEnd()</code>.
|
||||
*/
|
||||
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
|
||||
* <code>super.gameDidReset()</code>.
|
||||
*/
|
||||
protected void gameDidReset ()
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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 <code>null</code>
|
||||
* if the game is not yet over. */
|
||||
public boolean[] winners;
|
||||
|
||||
/** The unique round identifier for the current round. */
|
||||
public int roundId;
|
||||
|
||||
|
||||
@@ -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 <code>players</code> field. */
|
||||
public static final String PLAYERS = "players";
|
||||
|
||||
/** The field name of the <code>winners</code> field. */
|
||||
public static final String WINNERS = "winners";
|
||||
|
||||
/** The field name of the <code>roundId</code> 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 <code>null</code>
|
||||
* 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 <code>winners</code> 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 <code>index</code>th element of
|
||||
* <code>winners</code> 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 <code>roundId</code> field be set to the specified
|
||||
* value. The local value will be updated immediately and an event
|
||||
|
||||
Reference in New Issue
Block a user