Tictactoe complete
Difficulty:
By now, you should have a game that does everything except determine whether the game is over.
The exit criterion for the large while loop is that a 0 is entered. You are going to replace this exit criterion.
Below are some tips:
- First, find out on a paper or whiteboard what the possible situations are where the game ends.
- Consider which variables you need to perform this check.
- Replace the current exit criterion with a boolean gameOver, set this to true for now. You can then end the game with the stop button. Test this before continuing.
- Consider where in the big while loop this boolean should get a real value.
- Write the code to determine that value.
- Tip: use separate methods for this to keep the code understandable.
- And don’t forget to catch the entry 0 as incorrect entry.
Example
There is a winner
It’s a draw
Relevant links