Game Development Reference
In-Depth Information
Who won?
For every move any of the players make, we need to check if the player won (the
player was able to put three of their symbols in a straight line.) We need to check if
there are three of the same kind of symbol in the same row, or in the same column, or
along the diagonals.
Note that we perform this check in the onPlayerMoved method. This method is
called when either the player or the opponent makes a move.
private function checkGameEnd():void {
var status:int = checkGameStatus();
var gc:GameClient;
gc = PulseGame.getInstance().getGameClient();
if ( status != TictactoeGameStatus.CONTINUE) {
if ( status == TictactoeGameStatus.HOST_WIN ||
status == TictactoeGameStatus.GUEST_WIN ) {
var iWin1:Boolean, iWin2:Boolean;
iWin1 = (status==TictactoeGameStatus.
HOST_WIN && gc.isGameHost());
iWin2 = (status==TictactoeGameStatus.
GUEST_WIN && !gc.isGameHost());
if ( iWin1 || iWin2 ) {
// I win!
var av:GameAvatarClient;
av = gc.getMyAvatar();
// APPLY THE SCORE!
av.setScore(av.getScore()+1);
gc.publishMyAvatar();
showGameEnd(m_winSprite);
}
else {
// I loose!
showGameEnd(m_looseSprite);
}
}
else if ( status == TictactoeGameStatus.TIE ) {
// Game tied!
showGameEnd(m_tieSprite);
}
finishRound();
}
}
 
Search WWH ::




Custom Search