Tic-Tac-Toe: 2D array

This will be a text based implementation but would be easy to port into a graphic based version.

TicTacToe2.java

  1. Complete the constructor so the board can be any size, not just 3 by 3. Read the comments for details
  2. complete the changePlayer method.
  3. complete the mark method, that only replaces the grid location with the letter stored in player if it currently has a space. call the changePlayer method (Don't reduplicate code inside the mark method).
  4. complete the getPlayer method
  5. make a method called movesRemaining that returns the number of spaces in grid. Try using an enhanced (“for-each”) for loop.
  6. write a main method that makes an instance of the TicTacToe2 class and the calls the print method:

public static void main(String[] args)

At this point you can test your code with TicTacToeTexGame.java to see if you can put “X” and “O” in all 9 squares. Without completing the winner method, it will end with a cat's game every time. Try making sure it does not allow overwriteing a square that already has an “X” or a “O”.

Next we can work on the game, and the testing the winner() method of the TicTacToe2 class.

TicTacToeTexGame.java

WinnerTester.java