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
* 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. */
public static final int IN_PLAY = 1;
@@ -89,9 +89,9 @@ public class GameObject extends PlaceObject
/** Provides general game invocation services. */
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}. */
public int state;
public int state = PRE_GAME;
/** Indicates whether or not this game is rated. */
public boolean isRated;
@@ -315,7 +315,7 @@ public class GameManager extends PlaceManager
Name name = getPlayerName(playerIdx);
return (name == null) ? null : CrowdServer.lookupBody(name);
}
/**
* Sets the specified player as an AI with the specified
* configuration. It is assumed that this will be set soon after the
@@ -355,7 +355,7 @@ public class GameManager extends PlaceManager
}
/**
* Returns the player index of the given user in the game, or
* Returns the player index of the given user in the game, or
* <code>-1</code> if the player is not involved in the game.
*/
public int getPlayerIndex (Name username)
@@ -431,8 +431,7 @@ public class GameManager extends PlaceManager
String msgbundle, String msg, boolean waitForStart)
{
if (waitForStart &&
((_gameobj == null) ||
(_gameobj.state == GameObject.AWAITING_PLAYERS))) {
((_gameobj == null) || (_gameobj.state == GameObject.PRE_GAME))) {
// queue up the message.
if (_startmsgs == null) {
_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
// already done so
if (!isPartyGame() &&
_gameobj.state == GameObject.AWAITING_PLAYERS) {
if (!isPartyGame() && _gameobj.state == GameObject.PRE_GAME) {
startGame();
}
}
@@ -624,7 +622,7 @@ public class GameManager extends PlaceManager
protected void checkForNoShows ()
{
// nothing to worry about if we're already started
if (_gameobj.state != GameObject.AWAITING_PLAYERS) {
if (_gameobj.state != GameObject.PRE_GAME) {
return;
}
@@ -740,7 +738,7 @@ public class GameManager extends PlaceManager
{
// initialize the player status
_gameobj.setPlayerStatus(new int[getPlayerSlots()]);
// increment the round identifier
_gameobj.setRoundId(_gameobj.roundId + 1);
@@ -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
* classes can override this to put whatever wheels they might need
@@ -941,7 +965,7 @@ public class GameManager extends PlaceManager
{
return (_gameobj.state == GameObject.GAME_OVER);
}
/**
* Called when the game is about to end, but before the game end
* notification has been delivered to the players. Derived classes
@@ -984,7 +1008,7 @@ public class GameManager extends PlaceManager
if (shouldConcludeGame() && winnerCount > 0 && !_gameobj.isDraw()) {
reportWinnersAndLosers();
}
// calculate ratings and all that...
}
@@ -1020,7 +1044,7 @@ public class GameManager extends PlaceManager
}
}
}
/**
* Called when the game is to be reset to its starting state in
* preparation for a new game without actually ending the current
@@ -1124,22 +1148,8 @@ public class GameManager extends PlaceManager
public void attributeChanged (AttributeChangedEvent event)
{
if (event.getName().equals(GameObject.STATE)) {
switch (_committedState = event.getIntValue()) {
case GameObject.IN_PLAY:
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;
}
stateDidChange(_committedState = event.getIntValue(),
((Integer)event.getOldValue()).intValue());
}
}