Question: Tic - Tac - Toe Game Write a program that allows two players to play a game of tic - tac - toe. Use a
TicTacToe Game
Write a program that allows two players to play a game of tictactoe. Use a twe. dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk The program should run loop that does the following:
Displays the contents of the board array.
Allows player to select a location on the board for an X The program should alk the user to enter the row and column numbers.
Allows player to select a location on the board for an O The program should ask the user to enter the row and column numbers.
Determines whether a player has won, or a tie has occurred. If a player has won, the program should declare that player the winner and end. If a tie has occurred, the program should display an appropriate message and end.
Player wins when there are three Xs in a row on the game board. The Xs can appear in row, in a column, or diagonally across the board. Player wins when there are three in a row on the game board. The Os can appear in a row, in a column, or diagonally across the board. A tie occurs when all of the locations on the board are full, but there is no winner.
A D array is required to store the board and needs to be passed between functions.
You nut have the following functions.
void loadchar b; stores the values in the initial board so the user con select a number position to place an X or an O
void displayconst char b; displays the current status of the board
bool validmoveconst char b int pos; verifies that the position is in the range and has not already been taken
bool winnerconst char ; checks after each play to see if X or O has won the game
additional functions can be added if needed
The game needs to allow for the user to replay
Displaying the board needs to be visually appealing by either drawing the board or spacing appropriately
Things to consider when developing the game
If the user inputs an invalid position either off the board or already taken the user needs to be able to reenter their choice
When someone wins a message needs to be displayed and the game ends
If the board is full and there is not a winner a message stating the game was a draw needs to be displayed
Player where do you want to play?
Player where do you want to play?
That is not on the board.
Player where do you want to play?
That possition has already been played.
Player O where do you want to play?
Player X where do you want to play?
lote: The int is not the same as the char The ASCII value of char is int You can find all of the ASCII values in the chart on pages
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
