Game Development Reference
In-Depth Information
Implementing a turn-based game
Remember that the PulseGame also implements the GameClientCallback interface,
which means that when any notification is received by the client from the server, the
appropriate callback method is invoked on the implementing instance.
Since tic-tac-toe is a turn-based game (see subclass details of
TictactoeNewGameScreen ), the Pulse API fires a callback to let the client know that
it is now the player's turn. During this time, a visual hint should be displayed to the
player.
public override function onPlayerTurn():void {
(m_gameScreen as TictactoeGameScreen).onPlayerTurn();
}
The logic here in this class is to simply call the game screen to display the hint.
Sending and receiving player actions
There are two methods that need to be implemented, one to receive the action of
another player and the other to send the action to the other player.
To receive the action of another player, we simply override the onGameStateAction
and pass it to the game screen.
public override function onGameStateAction(gameState:GameStateClient)
:void{
(m_gameScreen as TictactoeGameScreen).onPlayerMoved(gameState);
}
To send the player action, we write a convenience sendGameState method, which
is called by the game screen object. During this time, we also tell the server that
the player's turn is done so that the server can inform about the next player's turn.
Note that the PutClient was defined in the schema file and generated during code
generation phase.
public function sendGameState(xPos:int,yPos:int,value:int):void {
var putMsg:PutClient = new PutClient();
putMsg.setStateType(GameConstants.GS_IS_UNIQUE);
putMsg.setPutRow(xPos);
putMsg.setPutColumn(yPos);
putMsg.setPutValue(value);
m_netClient.sendGameStateAction(putMsg);
m_netClient.nextTurn();
}
 
Search WWH ::




Custom Search