Displaying Player Turn:
public function onPlayerTurn():void {
// show the turn indicator
m_showingTurn = true;
addChild(m_turnSprite);
}
This method is called from the PulseGame object. When the server indicates that it is players turn to play, we show the Your Turn sprite to the player.
Letting the player making the move:
private function playAction(event:MouseEvent):void {
var gc:GameClient = PulseGame.getInstance().getGameClient();
if (gc.isMyTurn() == true) {
var selectedSprite:TictactoeHotspot;
selectedSprite = event.target as TictactoeHotspot;
if ( selectedSprite == null )
return;
var xPos:int = selectedSprite.col;
var yPos:int = selectedSprite.row;
if(m_hotspotArray[xPos][yPos].value == 0) {
m_tictactoeGame.sendGameState(xPos, yPos, m_putValue);
m_showingTurn = false;
removeChild(m_turnSprite);
}
}
}
We handle the mouse click, do a few checks, first is to check if it is indeed the players turn to move, if not we simply ignore it, second we check if the click is any of the empty (valid) spot, if everything checks out ok, we send the player action to the server and in turn the server will send the game state to the player itself and to the other player.
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();
}
Good luck on your new multi-player flash game!
» Level Intermediate |
Added: 2009-02-21 Rating: 6.04 Votes: 28 |
» Author |
Prashanth Hirematada is the founder & Chief Architect of Gamantra, a game technology company. |
» Download |
Download the files used in this tutorial. |
Download (0 kb) |
» Forums |
More help? Search our boards for quick answers! |