Question
Need Help! Tic-tac-toe. Write a game of tic-tac-toe in a class called TicTacToe. An object of type TicTacToe is a single game. Store the game
Need Help!
Tic-tac-toe. Write a game of tic-tac-toe in a class called TicTacToe. An object of type TicTacToe is a single game. Store the game board as a single 2-D array (3x3) of base type char. Use good data encapsulation practices and provide a public interface for methods that:
a. add a move b. display the board c. determine whose turn it is (X or O) d. determine if there is a winner e. say who the winner is f. reinitialize the game to the beginning
Write a main method for the class that will allow 2 players to enter moves in turn at the same keyboard. Allow the players to play multiple games. Be sure to test each method individually as you go, and avoid duplicate code. For full credit, include error checking to ensure a move is within the array bounds and not already played. Also be sure to end the game if it is a draw (this can be done by writing a method to check for a draw or by counting moves).
Here is an example of what the first move might look like:
Enter the row (1-3) for X: 1 Enter the column (1-3) for X: 3 | | X ----------- | | ----------- | | Enter the row (1-3) for O: ...
**** I'm just a beginner programmer. In class we just went over multi-dimensional arrays. And we've been using two classes per program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started