Question: Write a java program that simulates a two player Tic Toe game as well as allows play. The program will: The program will prompt for
Write a java program that simulates a two player Tic Toe game as well as allows play.
The program will:
- The program will prompt for input, alternate in placing an X or an O onto the board, until the board is filled, a tie occurs, X or O wins, or the user quits the game.
- The program will declare a tie if all cells in the board are filled, and will declare the winner if X or O has won the game.
- After each user's turn the program should print the current board state, and a terminal message if the game is over for any of the above reasons.
Three classes need to be implemented at the least
- TicTacToe
- which has the main() will ask user to select auto or manual play mode, and start a game in the users selection.
- TicTacToeTester
- which has the following methods
- int play(Scanner in) that will execute one iteration of the game and return, that is it will accept input from X via console, filling the board and printing out the resulting board, and then accept input from O via console, and filling the board and printing out the resulting board, and print out a result message if necessary, and return. Therefore, it has to be called in a loop by the caller to continue the game. It will return status codes about the state of the game, such as a tie, won by X, won by O.
- void play_auto(Scanner in) will execute all iterations of the game at once, print out the result message, and return. It will read the inputs of X and O from the given input file parameter.
- which has the following methods
- Board
-
will keep the board structure using a reference variable data field to a 2D array (not an ArrrayList!). It will have its required constructors to initialize the board. Some of the methods of the Board class that you should implement are as follows, you may add new ones if needed:
-
- String toString() - returns a String representing the board array in a human-readable format
- boolean isFull() - returns true if all cells in the array are filled, false if not
- boolean isTie() - returns true if it is a tie, false if not.
-
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
