Define a class called TicTacToe. An object of type TicTacToe is a single game of tic-tac-toe. Store the game board as a single two-dimensional array of base type char that has three rows and three columns. Include methods to add a move, to display the board, to tell whose turn it is (X or O), to tell whether there is a winner, to say who the winner is, and to reinitialize the game to the beginning. Write a main method for the class that will allow two players to enter their moves in turn at the same keyboard.
This project is one of the most sophisticated problems in the text and is complex enough that a good, disciplined step-wise approach is particularly useful. The challenge is to break up the actions into manageable pieces and write methods for them. The goal is to create methods that are easy to use, logically written, and make main easy to write and read. It is helpful to write main as a sequence of method calls to do things (like clear the board for a new game, draw the board, enter an X or O on the board, check for a winner, etc.) without actually writing complete code for the methods. Instead, just write stubs with just a line that prints out its method name and, if it has a return type other than void, returns a fixed value. Then proceed to add functionality one method at a time. A good approach is to write the code to display the board first, then the code to clear it to start a new game, then the code to get an entry and insert it into the board, etc. The test for a winning move can be the last part implemented – it is easier work on that algorithm and code if everything is working.
See the code in TicTacToe.java.
You might also like to view...
A cell located in the third row and forth column is named _____.
A. 3D B. C4 C. D3 D. 4C
Terminate the process identified by process ID 12345
What will be an ideal response?
Safe Mode can be used to help troubleshoot a computer system
Indicate whether the statement is true or false
Context-sensitive commands are displayed by ________
A) shortcut menus B) ScreenTips C) dialog boxes D) content panes