Game Development Reference
In-Depth Information
The previous method (checkGameEnd) checks if the game was won by either of
the player or was tied. The status tells us the current status of the game. The status
values can be one of the values from the TictactoeGameStatus :
CONTINUE
HOST_WIN
GUEST_WIN
TIE
If the status is CONTINUE , then the game can still be played. HOST_WIN or GUEST_WIN
indicates who won the game already. TIE , in case all the spots are marked and there
was no winner. Note that when we determine that this player has won the game, we
increase the score by 1 and call the Pulse API, publishMyAvatar .
The status itself is determined by the checkGameStatus method called at the
beginning of the checkEndGame method.
private function checkGameStatus():int {
var ret:int,totalBit:int = 0;
for(var row:int = 0;row < 3;row++) {
for(var column:int = 0;column < 3;column++) {
ret = checkCell(row,column);
if(ret == 3)
return TictactoeGameStatus.HOST_WIN;
else if(ret == -3)
return TictactoeGameStatus.GUEST_WIN;
else
totalBit += ret;
}
}
if(totalBit == 9) {
markWin(4, -1);
return TictactoeGameStatus.TIE;
}
else
return TictactoeGameStatus.CONTINUE;
}
The above method (checkGameStatus) adds the value of the marks along all possible
rows, columns, and diagonally. If the sum of the values adds up to 3, then the host
has won; if it is -3, the guest has won.
 
Search WWH ::




Custom Search