1.1-Introductie-Programmeren

Tictactoe complete

Difficulty: Filled Outlined Outlined

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:

  1. First, find out on a paper or whiteboard what the possible situations are where the game ends.
  2. Consider which variables you need to perform this check.
  3. 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.
  4. Consider where in the big while loop this boolean should get a real value.
  5. Write the code to determine that value.
    • Tip: use separate methods for this to keep the code understandable.
  6. And don’t forget to catch the entry 0 as incorrect entry.

Example

There is a winner

example example

It’s a draw

example