Click-spamming for fun and profit
The human player can also cheat, and place an X during the pause while the computer is "thinking". Try "click-spamming" the grid to place more Xs than you ought to. If you're very quick, you can fill the grid with Xs before the computer places a single O.
By adding a conditional check to the ClickSquare
function, we can make sure the human can only place a piece when it's his or her turn:
function ClickSquare(square:GameObject) { if(gameIsOver || currentPlayer == 2) return;
The double-pipe means "OR". If either of the statements separated by || in the conditional check resolve to true, then the code within the conditional is executed.
So if the human clicks to place a piece, if either the game is over or it's the computer's turn, we use the return statement to eject out of the function and prevent the rest of the code from executing.
Test the game again. Now, neither player can cheat.