Added support for handling games with multiple rounds.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@237 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-03-11 07:59:23 +00:00
parent b6c6b74d73
commit 5b77f2f95d
11 changed files with 223 additions and 99 deletions
+48 -14
View File
@@ -58,6 +58,13 @@ import flash.display.DisplayObject;
*/
[Event(name="GameStarted", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when a round starts.
*
* @eventType com.threerings.ezgame.StateChangedEvent.ROUND_STARTED
*/
[Event(name="RoundStarted", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when the turn changes in a turn-based game.
*
@@ -65,6 +72,13 @@ import flash.display.DisplayObject;
*/
[Event(name="TurnChanged", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when a round ends.
*
* @eventType com.threerings.ezgame.StateChangedEvent.ROUND_ENDED
*/
[Event(name="RoundEnded", type="com.threerings.ezgame.StateChangedEvent")]
/**
* Dispatched when the game ends.
*
@@ -254,7 +268,9 @@ public class EZGameControl extends BaseControl
var scl :StateChangedListener = (obj as StateChangedListener);
addEventListener(StateChangedEvent.CONTROL_CHANGED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.GAME_STARTED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.ROUND_STARTED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.TURN_CHANGED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.ROUND_ENDED, scl.stateChanged, false, 0, true);
addEventListener(StateChangedEvent.GAME_ENDED, scl.stateChanged, false, 0, true);
}
if (obj is OccupantChangedListener) {
@@ -282,12 +298,11 @@ public class EZGameControl extends BaseControl
}
if (obj is StateChangedListener) {
var scl :StateChangedListener = (obj as StateChangedListener);
removeEventListener(
StateChangedEvent.GAME_STARTED, scl.stateChanged);
removeEventListener(
StateChangedEvent.TURN_CHANGED, scl.stateChanged);
removeEventListener(
StateChangedEvent.GAME_ENDED, scl.stateChanged);
removeEventListener(StateChangedEvent.GAME_STARTED, scl.stateChanged);
removeEventListener(StateChangedEvent.ROUND_STARTED, scl.stateChanged);
removeEventListener(StateChangedEvent.TURN_CHANGED, scl.stateChanged);
removeEventListener(StateChangedEvent.ROUND_ENDED, scl.stateChanged);
removeEventListener(StateChangedEvent.GAME_ENDED, scl.stateChanged);
}
if (obj is OccupantChangedListener) {
var ocl :OccupantChangedListener = (obj as OccupantChangedListener);
@@ -426,6 +441,15 @@ public class EZGameControl extends BaseControl
return int(callEZCode("getTurnHolder_v1"));
}
/**
* Returns the current round number. Rounds start at 1 and increase if the game calls {@link
* #endRound} with a next round timeout.
*/
public function getRound () :int
{
return int(callEZCode("getRound_v1"));
}
/**
* Get the user-specific game data for the specified user. The first time this is requested per
* game instance it will be retrieved from the database. After that, it will be returned from
@@ -476,6 +500,15 @@ public class EZGameControl extends BaseControl
callEZCode("endTurn_v2", nextPlayerId);
}
/**
* Ends the current round. If nextRoundDelay is greater than zero, the next round will be
* started in the specified number of seconds.
*/
public function endRound (nextRoundDelay :int = -1) :void
{
callEZCode("endRound_v1", nextRoundDelay);
}
/**
* End the game. The specified player ids are winners!
*/
@@ -494,8 +527,8 @@ public class EZGameControl extends BaseControl
o["controlDidChange_v1"] = controlDidChange_v1;
o["turnDidChange_v1"] = turnDidChange_v1;
o["messageReceived_v1"] = messageReceived_v1;
o["gameDidStart_v1"] = gameDidStart_v1;
o["gameDidEnd_v1"] = gameDidEnd_v1;
o["gameStateChanged_v1"] = gameStateChanged_v1;
o["roundStateChanged_v1"] = roundStateChanged_v1;
o["dispatchEvent_v1"] = dispatch;
o["occupantChanged_v1"] = occupantChanged_v1;
}
@@ -506,8 +539,7 @@ public class EZGameControl extends BaseControl
private function propertyWasSet_v1 (
name :String, newValue :Object, oldValue :Object, index :int) :void
{
dispatch(
new PropertyChangedEvent(this, name, newValue, oldValue, index));
dispatch(new PropertyChangedEvent(this, name, newValue, oldValue, index));
}
/**
@@ -537,17 +569,19 @@ public class EZGameControl extends BaseControl
/**
* Private method to post a StateChangedEvent.
*/
private function gameDidStart_v1 () :void
private function gameStateChanged_v1 (started :Boolean) :void
{
dispatch(new StateChangedEvent(StateChangedEvent.GAME_STARTED, this));
dispatch(new StateChangedEvent(started ? StateChangedEvent.GAME_STARTED :
StateChangedEvent.GAME_ENDED, this));
}
/**
* Private method to post a StateChangedEvent.
*/
private function gameDidEnd_v1 () :void
private function roundStateChanged_v1 (started :Boolean) :void
{
dispatch(new StateChangedEvent(StateChangedEvent.GAME_ENDED, this));
dispatch(new StateChangedEvent(started ? StateChangedEvent.ROUND_STARTED :
StateChangedEvent.ROUND_ENDED, this));
}
/**
@@ -34,6 +34,13 @@ public class StateChangedEvent extends EZEvent
/** Indicates that the game has transitioned to a ended state. */
public static const GAME_ENDED :String = "GameEnded";
/** Indicates that a round has started. Games that do not require multiple rounds can ignore
* this event. */
public static const ROUND_STARTED :String = "RoundStarted";
/** Indicates that the current round has ended. */
public static const ROUND_ENDED :String = "RoundEnded";
/** Indicates that a new controller has been assigned. */
public static const CONTROL_CHANGED :String = "ControlChanged";
@@ -34,6 +34,7 @@ import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.parlor.game.client.GameController;
import com.threerings.parlor.game.data.GameObject;
import com.threerings.parlor.turn.client.TurnGameController;
import com.threerings.parlor.turn.client.TurnGameControllerDelegate;
@@ -88,6 +89,12 @@ public class EZGameController extends GameController
var name :String = event.getName();
if (EZGameObject.CONTROLLER_OID == name) {
_panel.backend.controlDidChange();
} else if (GameObject.ROUND_ID == name) {
if ((event.getValue() as int) > 0) {
_panel.backend.roundStateChanged(true);
} else {
_panel.backend.roundStateChanged(false);
}
} else {
super.attributeChanged(event);
}
@@ -113,14 +120,14 @@ public class EZGameController extends GameController
override protected function gameDidStart () :void
{
super.gameDidStart();
_panel.backend.gameDidStart();
_panel.backend.gameStateChanged(true);
}
// from GameController
override protected function gameDidEnd () :void
{
super.gameDidEnd();
_panel.backend.gameDidEnd();
_panel.backend.gameStateChanged(false);
}
// from PlaceController
@@ -45,6 +45,9 @@ public interface EZGameService extends InvocationService
// from Java interface EZGameService
function endGame (arg1 :Client, arg2 :Array, arg3 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService
function endRound (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void;
// from Java interface EZGameService
function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void;
@@ -192,8 +192,10 @@ public class GameControlBackend
o["getControllerId_v1"] = getControllerId_v1;
o["getUserCookie_v2"] = getUserCookie_v2;
o["endTurn_v2"] = endTurn_v2;
o["endRound_v1"] = endRound_v1;
o["endGame_v2"] = endGame_v2;
o["getTurnHolder_v1"] = getTurnHolder_v1;
o["getRound_v1"] = getRound_v1;
o["getOccupantName_v1"] = getOccupantName_v1;
o["getPlayers_v1"] = getPlayers_v1;
o["getPlayerPosition_v1"] = getPlayerPosition_v1;
@@ -347,6 +349,11 @@ public class GameControlBackend
return (occInfo == null) ? 0 : occInfo.bodyOid;
}
public function getRound_v1 () :int
{
return _ezObj.roundId;
}
public function getUserCookie_v2 (
playerId :int, callback :Function) :void
{
@@ -401,8 +408,14 @@ public class GameControlBackend
public function endTurn_v2 (nextPlayerId :int) :void
{
_ezObj.ezGameService.endTurn(_ctx.getClient(), nextPlayerId,
createLoggingConfirmListener("endTurn"));
_ezObj.ezGameService.endTurn(
_ctx.getClient(), nextPlayerId, createLoggingConfirmListener("endTurn"));
}
public function endRound_v1 (nextRoundDelay :int) :void
{
_ezObj.ezGameService.endRound(
_ctx.getClient(), nextRoundDelay, createLoggingConfirmListener("endRound"));
}
public function endGame_v2 (... winnerIds) :void
@@ -411,12 +424,11 @@ public class GameControlBackend
while (winnerIds.length > 0) {
winners.push(int(winnerIds.shift()));
}
_ezObj.ezGameService.endGame(_ctx.getClient(), winners,
createLoggingConfirmListener("endGame"));
_ezObj.ezGameService.endGame(
_ctx.getClient(), winners, createLoggingConfirmListener("endGame"));
}
public function getDictionaryLetterSet_v1 (
locale :String, count :int, callback :Function) :void
public function getDictionaryLetterSet_v1 (locale :String, count :int, callback :Function) :void
{
var listener :InvocationService_ResultListener;
if (callback != null) {
@@ -682,19 +694,25 @@ public class GameControlBackend
}
/**
* Called by the EZGameController when the game starts.
* Called by the EZGameController when the game starts or ends.
*/
public function gameDidStart () :void
public function gameStateChanged (started :Boolean) :void
{
callUserCode("gameDidStart_v1");
if (started && _userFuncs["gameDidStart_v1"] != null) {
callUserCode("gameDidStart_v1"); // backwards compatibility
} else if (!started && _userFuncs["gameDidEnd_v1"] != null) {
callUserCode("gameDidEnd_v1"); // backwards compatibility
} else {
callUserCode("gameStateChanged_v1", started); // new hotness
}
}
/**
* Called by the EZGameController when the game ends.
* Called by the EZGameController when a round starts or ends.
*/
public function gameDidEnd () :void
public function roundStateChanged (started :Boolean) :void
{
callUserCode("gameDidEnd_v1");
callUserCode("roundStateChanged_v1", started);
}
// from SetListener
@@ -83,8 +83,21 @@ public class EZGameMarshaller extends InvocationMarshaller
]);
}
/** The method id used to dispatch {@link #endRound} requests. */
public static const END_ROUND :int = 4;
// from interface EZGameService
public function endRound (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
{
var listener3 :InvocationMarshaller_ListenerMarshaller = new InvocationMarshaller_ListenerMarshaller();
listener3.listener = arg3;
sendRequest(arg1, END_ROUND, [
Integer.valueOf(arg2), listener3
]);
}
/** The method id used to dispatch {@link #endTurn} requests. */
public static const END_TURN :int = 4;
public static const END_TURN :int = 5;
// from interface EZGameService
public function endTurn (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -97,7 +110,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #getCookie} requests. */
public static const GET_COOKIE :int = 5;
public static const GET_COOKIE :int = 6;
// from interface EZGameService
public function getCookie (arg1 :Client, arg2 :int, arg3 :InvocationService_InvocationListener) :void
@@ -110,7 +123,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #getDictionaryLetterSet} requests. */
public static const GET_DICTIONARY_LETTER_SET :int = 6;
public static const GET_DICTIONARY_LETTER_SET :int = 7;
// from interface EZGameService
public function getDictionaryLetterSet (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_ResultListener) :void
@@ -123,7 +136,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #getFromCollection} requests. */
public static const GET_FROM_COLLECTION :int = 7;
public static const GET_FROM_COLLECTION :int = 8;
// from interface EZGameService
public function getFromCollection (arg1 :Client, arg2 :String, arg3 :Boolean, arg4 :int, arg5 :String, arg6 :int, arg7 :InvocationService_ConfirmListener) :void
@@ -136,7 +149,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #mergeCollection} requests. */
public static const MERGE_COLLECTION :int = 8;
public static const MERGE_COLLECTION :int = 9;
// from interface EZGameService
public function mergeCollection (arg1 :Client, arg2 :String, arg3 :String, arg4 :InvocationService_InvocationListener) :void
@@ -149,7 +162,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #sendMessage} requests. */
public static const SEND_MESSAGE :int = 9;
public static const SEND_MESSAGE :int = 10;
// from interface EZGameService
public function sendMessage (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :InvocationService_InvocationListener) :void
@@ -162,7 +175,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setCookie} requests. */
public static const SET_COOKIE :int = 10;
public static const SET_COOKIE :int = 11;
// from interface EZGameService
public function setCookie (arg1 :Client, arg2 :ByteArray, arg3 :InvocationService_InvocationListener) :void
@@ -175,7 +188,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setProperty} requests. */
public static const SET_PROPERTY :int = 11;
public static const SET_PROPERTY :int = 12;
// from interface EZGameService
public function setProperty (arg1 :Client, arg2 :String, arg3 :Object, arg4 :int, arg5 :Boolean, arg6 :Object, arg7 :InvocationService_InvocationListener) :void
@@ -188,7 +201,7 @@ public class EZGameMarshaller extends InvocationMarshaller
}
/** The method id used to dispatch {@link #setTicker} requests. */
public static const SET_TICKER :int = 12;
public static const SET_TICKER :int = 13;
// from interface EZGameService
public function setTicker (arg1 :Client, arg2 :String, arg3 :int, arg4 :InvocationService_InvocationListener) :void