1.1-Introductie-Programmeren

Tictactoe with ArrayList

Difficulty: Filled Outlined Outlined

The last time you worked on Tictactoe was in the sub-module Methods3. We are almost ready to finish the program. In this exercise we prepare the last phase, which is the phase where the program also determines whether someone has won. To make this possible, a number of things must be changed:

  1. Place the 9 fields of the game board in an ArrayList. When rewriting code, take advantage of the relationship between the ArrayList index and position on the board.
  2. Tip: To keep the code in the run method as clear as possible: place the initialization of the fields with the numbers in a separate method.
  3. Ensure that alternately player X and player O can make their moves.
  4. Tip: Asking the next move can be placed in a separate method.

The program now alternately sets X’s and O’s at the position entered by the user. If the user enters 0 the program will end. If the user enters a number that the program cannot act on, a notification is given and the same player can try again.

Example

example

example

example