Game Development Reference
In-Depth Information
Letting the player make the move
For each hotspot we saw earlier (in the init method), we subscribe the mouse click.
The callback method is set to be the previous method, playAction . First, we check
if it is indeed the player's turn to move. If not, we simply ignore it. Second, we check
if the clicked hotspot is an empty one. If so, we send the player action to the server,
which in turn will send the game state to the player itself and to the other player.
private function playAction(event:MouseEvent):void {
var gc:GameClient;
gc = PulseGame.getInstance().getGameClient();
if (gc.isMyTurn() == true) {
var sel:TictactoeHotspot;
sel = event.target as TictactoeHotspot;
if (sel == null )
return;
var xPos:int = sel.col;
var yPos:int = sel.row;
if ( m_hotspotArray[xPos][yPos].value == 0 ) {
m_tictactoeGame.
sendGameState(xPos, yPos, m_putValue);
removeChild(m_turnSprite);
}
}
}
When the player action is received by the client, the TictactoeGame (refer above)
object calls the following method. The implementation here simply updates the
screen and checks if the game was won, lost, or tied.
public function onPlayerMoved(gameState:GameStateClient):void {
var putMsg:PutClient = gameState as PutClient;
showSprite(putMsg.getPutRow(),
putMsg.getPutColumn(),
putMsg.getPutValue());
checkGameEnd();
}
 
Search WWH ::




Custom Search