Prev | Current Page 823 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


import haxe.remoting.SocketConnection;
class GameBoard
{
public var grid(default, null) : Array < Array < Int > > ;
private var results : Array < Int > ;
private var moves : Int;
public function new()
{
grid = [[0, 0, 0],[0, 0, 0],[0, 0, 0]];
results = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
moves = 0;
}
public function place(isPlayerOne : Bool, row : Int, col : Int) : Bool
{
if( grid[row][col] != 0 )
return false;
var point = if(isPlayerOne) 1 else -1;
grid[row][col] = point;
results[row] += point; // cumulate points for rows
results[3+col] += point; // cumulate points for cols
results[8+row-col] += point; // cumulate points for first diagonal
results[15-row-col] += point; // cumulate points for second diagonal
moves++;
return true;
}
public function checkTie() : Bool
{
return moves == 9;
}
(continued)
Part II: Server Side, JavaScript, and Flash: Oh My!
446
public function checkWinner() : Bool
{
for(r in results)
if(r == 3 || r == -3)
return true;
return false;
}
}
In the GameClient.


Pages:
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835