Nice moves
It seems simple enough to create an int
variable to keep track of the number of moves that have been made, which we'll increment every time a player places a piece. If we're up to the ninth move with no winner, that means all of the squares have been filled and we've reached a stalemate.
At the top of the script, declare a moves
variable:
var gameIsOver:boolean;
var moves:int;
Just above the Instantiate
command in the ClickSquare
function, increment moves
:
moves ++;
Instantiate(piece, square.transform.position, Quaternion.identity);
Tack on an else
to the
CheckForWin
condition check that ends the game if we've reached 9 moves with no winner:
if(CheckForWin(square)) { gameIsOver = true; ShowWinnerPrompt(); return; } else if(moves >= 9) { gameIsOver = true; ShowStalematePrompt(); return; }
Why are we checking if moves
is equal to or greater than 9? Isn't that impossible? Yes it is, but I've adopted the habit of being abundantly confident in my condition checks to cover...