Changed AWAITING_PLAYERS to PRE_GAME; factored some code into stateDidChange().

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3787 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-12-20 01:45:02 +00:00
parent ecc5c40e73
commit c7d36f9705
2 changed files with 40 additions and 30 deletions
@@ -67,7 +67,7 @@ public class GameObject extends PlaceObject
/** A game state constant indicating that the game has not yet started /** A game state constant indicating that the game has not yet started
* and is still awaiting the arrival of all of the players. */ * and is still awaiting the arrival of all of the players. */
public static final int AWAITING_PLAYERS = 0; public static final int PRE_GAME = 0;
/** A game state constant indicating that the game is in play. */ /** A game state constant indicating that the game is in play. */
public static final int IN_PLAY = 1; public static final int IN_PLAY = 1;
@@ -89,9 +89,9 @@ public class GameObject extends PlaceObject
/** Provides general game invocation services. */ /** Provides general game invocation services. */
public GameMarshaller gameService; public GameMarshaller gameService;
/** The game state, one of {@link #AWAITING_PLAYERS}, {@link #IN_PLAY}, /** The game state, one of {@link #PRE_GAME}, {@link #IN_PLAY},
* {@link #GAME_OVER}, or {@link #CANCELLED}. */ * {@link #GAME_OVER}, or {@link #CANCELLED}. */
public int state; public int state = PRE_GAME;
/** Indicates whether or not this game is rated. */ /** Indicates whether or not this game is rated. */
public boolean isRated; public boolean isRated;
@@ -431,8 +431,7 @@ public class GameManager extends PlaceManager
String msgbundle, String msg, boolean waitForStart) String msgbundle, String msg, boolean waitForStart)
{ {
if (waitForStart && if (waitForStart &&
((_gameobj == null) || ((_gameobj == null) || (_gameobj.state == GameObject.PRE_GAME))) {
(_gameobj.state == GameObject.AWAITING_PLAYERS))) {
// queue up the message. // queue up the message.
if (_startmsgs == null) { if (_startmsgs == null) {
_startmsgs = new ArrayList(); _startmsgs = new ArrayList();
@@ -609,8 +608,7 @@ public class GameManager extends PlaceManager
{ {
// start up the game if we're not a party game and if we haven't // start up the game if we're not a party game and if we haven't
// already done so // already done so
if (!isPartyGame() && if (!isPartyGame() && _gameobj.state == GameObject.PRE_GAME) {
_gameobj.state == GameObject.AWAITING_PLAYERS) {
startGame(); startGame();
} }
} }
@@ -624,7 +622,7 @@ public class GameManager extends PlaceManager
protected void checkForNoShows () protected void checkForNoShows ()
{ {
// nothing to worry about if we're already started // nothing to worry about if we're already started
if (_gameobj.state != GameObject.AWAITING_PLAYERS) { if (_gameobj.state != GameObject.PRE_GAME) {
return; return;
} }
@@ -752,6 +750,32 @@ public class GameManager extends PlaceManager
}); });
} }
/**
* Called when the game state changes. This happens after the attribute
* change event has propagated.
*
* @param state the new game state.
* @param oldState the previous game state.
*/
protected void stateDidChange (int state, int oldState)
{
switch (state) {
case GameObject.IN_PLAY:
gameDidStart();
break;
case GameObject.CANCELLED:
// fall through to GAME_OVER case
case GameObject.GAME_OVER:
// call gameDidEnd() only if the game was previously in play
if (oldState == GameObject.IN_PLAY) {
gameDidEnd();
}
break;
}
}
/** /**
* Called after the game start notification was dispatched. Derived * Called after the game start notification was dispatched. Derived
* classes can override this to put whatever wheels they might need * classes can override this to put whatever wheels they might need
@@ -1124,22 +1148,8 @@ public class GameManager extends PlaceManager
public void attributeChanged (AttributeChangedEvent event) public void attributeChanged (AttributeChangedEvent event)
{ {
if (event.getName().equals(GameObject.STATE)) { if (event.getName().equals(GameObject.STATE)) {
switch (_committedState = event.getIntValue()) { stateDidChange(_committedState = event.getIntValue(),
case GameObject.IN_PLAY: ((Integer)event.getOldValue()).intValue());
gameDidStart();
break;
case GameObject.CANCELLED:
// fall through to GAME_OVER case
case GameObject.GAME_OVER:
// Call gameDidEnd only if it was actually started
if (((Integer)event.getOldValue()).intValue() ==
GameObject.IN_PLAY) {
gameDidEnd();
}
break;
}
} }
} }