tictactoe2
Tic-Tac-Toe: 2D array
This will be a text based implementation but would be easy to port into a graphic based version.
- Complete the constructor so the board can be any size, not just 3 by 3. Read the comments for details
- complete the
changePlayermethod. - complete the
markmethod, that only replaces the grid location with the letter stored inplayerif it currently has a space. call thechangePlayermethod (Don't reduplicate code inside themarkmethod). - complete the
getPlayermethod - make a method called
movesRemainingthat returns the number of spaces ingrid. Try using an enhanced (“for-each”) for loop. - write a main method that makes an instance of the TicTacToe2 class and the calls the
printmethod:
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.
tictactoe2.txt · Last modified: 2024/11/13 17:33 by frchris