GameSubControl: Difference between revisions
(Created page with "The largest of the subcontrols, the '''[http://www.whirled.com/code/asdocs/com/whirled/game/GameSubControl.html GameSubControl]''' is mainly concerned with the life cycles of...") |
Whirled vox (talk | contribs) m (Text replacement - ">" to ">") |
||
| Line 4: | Line 4: | ||
Never instantiate the GameSubcontrol directly, always access it via the [[GameControl]] object. For convenience, you can create a local handle to the GameSubControl Object; | Never instantiate the GameSubcontrol directly, always access it via the [[GameControl]] object. For convenience, you can create a local handle to the GameSubControl Object; | ||
<actionscript | <actionscript> | ||
public class MyGame extends Sprite { | public class MyGame extends Sprite { | ||
public MyGame () { | public MyGame () { | ||
| Line 15: | Line 15: | ||
protected _game :GameSubControl; | protected _game :GameSubControl; | ||
} | } | ||
</actionscript | </actionscript> | ||
== Starting the Game Manually == | == Starting the Game Manually == | ||
In order to start a game, each game client has to signal it's ready. Usually, this is done automagically when the client instantiates a new GameControl Object. However, it is possible to not send the signal until a later point. | In order to start a game, each game client has to signal it's ready. Usually, this is done automagically when the client instantiates a new GameControl Object. However, it is possible to not send the signal until a later point. | ||
<actionscript | <actionscript> | ||
//this sends the client ready signal automagically | //this sends the client ready signal automagically | ||
_ctrl = new GameControl(this); | _ctrl = new GameControl(this); | ||
</actionscript | </actionscript> | ||
<actionscript | <actionscript> | ||
//this does not send the client ready signal | //this does not send the client ready signal | ||
_ctrl = new GameControl(this, false); | _ctrl = new GameControl(this, false); | ||
| Line 34: | Line 34: | ||
_ctrl.game.playerReady(); | _ctrl.game.playerReady(); | ||
</actionscript | </actionscript> | ||
== Listening For Events == | == Listening For Events == | ||
| Line 50: | Line 50: | ||
By listening to these events, you can trigger logic specific to your game. These are especially important for multi-player games. For example, if you want to give each player/game client a new card on a turn basis, you can do the following | By listening to these events, you can trigger logic specific to your game. These are especially important for multi-player games. For example, if you want to give each player/game client a new card on a turn basis, you can do the following | ||
<actionscript | <actionscript> | ||
//added during the initalization | //added during the initalization | ||
| Line 66: | Line 66: | ||
} | } | ||
} | } | ||
</actionscript | </actionscript> | ||
== Adding And Selling Game Packs == | == Adding And Selling Game Packs == | ||
Revision as of 17:09, 5 September 2018
The largest of the subcontrols, the GameSubControl is mainly concerned with the life cycles of games: the beginning and ending of the game itself, of each separate round as well as player turns, for turn-based games. It's used to let Whirled know which players won, and with which scores, which in turn is used to calculate coin payouts for players using one of several distribution strategies.
Get the GameSubControl
Never instantiate the GameSubcontrol directly, always access it via the GameControl object. For convenience, you can create a local handle to the GameSubControl Object;
<actionscript> public class MyGame extends Sprite {
public MyGame () {
_ctrl = new GameControl(this);
_game = _ctrl.game;
}
protected _ctrl :GameControl; protected _game :GameSubControl;
} </actionscript>
Starting the Game Manually
In order to start a game, each game client has to signal it's ready. Usually, this is done automagically when the client instantiates a new GameControl Object. However, it is possible to not send the signal until a later point.
<actionscript>
//this sends the client ready signal automagically
_ctrl = new GameControl(this);
</actionscript>
<actionscript>
//this does not send the client ready signal
_ctrl = new GameControl(this, false);
.......
//at some later point, send the client is ready signal.
_ctrl.game.playerReady();
</actionscript>
Listening For Events
The following are the events that you can listen for on the GameSubControl object.
StateChangedEvent.CONTROL_CHANGED StateChangedEvent.GAME_ENDED StateChangedEvent.GAME_STARTED OccupantChangedEvent.OCCUPANT_ENTERED OccupantChangedEvent.OCCUPANT_LEFT StateChangedEvent.ROUND_ENDED StateChangedEvent.ROUND_STARTED StateChangedEvent.TURN_CHANGED UserChatEvent.USER_CHAT
By listening to these events, you can trigger logic specific to your game. These are especially important for multi-player games. For example, if you want to give each player/game client a new card on a turn basis, you can do the following <actionscript>
//added during the initalization
_ctrl.game.addEventListener(
StateChangedEvent.TURN_CHANGED, handleTurnChanged);
protected function handleTurnChanged (event :StateChangedEvent) :void
{
//Check to see if it is this game client's turn.
if (_ctrl.game.isMyTurn()]) {
handleOutNewCard();
//start the next turn
_ctrl.game.startNextTurn();
}
}
</actionscript>
Adding And Selling Game Packs
Game Creators can easily monetize their games by selling game packs as part of their game. The game can access information about its item packs and level packs via the gameSubControl. For player specific pack information, you should use the PlayerSubControl.
Ending The Game And Awarding Payouts
Coin payouts are also controlled via the GameSubControl. You can read more about coin payouts here. Currently the coin payouts are tied to the endGame call, but that will change soon.