Shave and a haircut
Thanks to the GetPlayer
function, we can shorten up our monstro code quite nicely. Add the following lines to the CheckForWin
function:
var theScript:Square = square.GetComponent.<Square>(); //Check the squares in the same column: if(GetPlayer(theScript.x,0) == currentPlayer && GetPlayer(theScript.x,1) == currentPlayer && GetPlayer(theScript.x,2) == currentPlayer) return true; // Check the squares in the same row: if(GetPlayer(0,theScript.y) == currentPlayer && GetPlayer(1,theScript.y) == currentPlayer && GetPlayer(2,theScript.y) == currentPlayer) return true;
That reduces our column and row checks to two somewhat long, but still much more manageable lines.
Finally, we'll hard-code the values in two more statements to check the diagonals, because checking the diagonals in some pithy, clever loop is a more trouble than it's worth:
function CheckForWin(square:GameObject):boolean { var theScript:Square = square.GetComponent.<Square...