Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do you design an object oriented project for the following program: A softwa

ID: 672356 • Letter: H

Question

how do you design an object oriented project for the following program: A software company that develops games has just hired you! Before working on the next version of Medieval Menace they have given you the task of implementing the tictac-toe game in C++. Tic-tac-toe consists of a 3 × 3 game board of squares where each square is either empty, has an X marker, or has a O marker. Two players represented by an X or an O play the game. The objective is for one player to get three Xs or three Os in a row first. Design, implement, and test classes that represent a tic-tac-toe game board and X and O markers. Your classes should provide suitable observer and mutator methods for modifying the game board and displaying the state of the game. Use your classes to create a game that prompts for player X and player O to place markers at specified locations on the game board. After each move your program should display the current game board to the console. Your program should also check after each move if there is a winning configuration of the game board. If so, the game should complete indicating which player won

Explanation / Answer

//The given code shows the Tic-Tac-Toe game.
#include <iostream.h>
#define X 'X' //Defined the macros to make output interactive
#define O 'O'
int yes =1;
int no= 0;
int check (char[][3], int, int); //Function to check the status of the board.
void counterattack (char arr[][3], char turn); //Attack function to react on the board.
void progress (char arr[][3]); //Display the progress of the borad

void main()
{
//Creating the array of the 3*3 borad.
char arr[3][3];
int rows,cols,correct=yes,turn,game=yes,counter=0,r,c,d;

//Lopping into the 2 dimensional array to play on the game.
for (rows=0; rows<3; rows++)
{
for (cols=0; cols<3; cols++)
{
arr[rows][cols]=' ';
}
}
cout << "Tic-Tac-Toe Program. " ;
cout << "Please pick the rows then after the column. ";
progress(arr);
do
{
do
{
turn=X;
cout << "Rows: ";
cin >> rows;
cout << "Column: ";
cin >> cols;
rows--;
cols--;
arr[rows][cols];
correct=check (arr,rows,cols);
if (!correct)
}while (!correct);
arr[rows][cols]=X;
counter++;
game=winlose(arr, game);
turn=O;
if (!game)
{
progress(arr);
cout << " You win!!! " << endl;
cin >> game;
game=go_on(game);
if (!game)
break;
}
if (game)
{
counteratk (arr, turn);
game=winlose(arr,game);
}
if (game==2)
{
cout << " You lost >.> " << endl;
cout << "Please Play again " << "1.yes" <<endl<< "0.no" <<endl<< endl;
cin >> game;
game=go_on(game);
if(!game)
break;
}
if (counter==5 && game)
{
cout << " A Tie!! " << endl<<endl;
cin >> game;
game=go_on(game);
if(!game)
break;
}
}while (game);
}
=============================================================
int go_on (int game)
{
if (game)
{
//It checks if there exists a game to play it will call the main method and play further
main();
{
//End the game here itself
return no;

int check (char arr[][3], int rows, int cols)
return no;
}

int winlose (char arr[][3], int game)
{
int rows, cols, r, c, d, ro, co, dO;
for (rows=0; rows<3; rows++)
{
r=0;
c=0;
d=0;
ro=0;
co=0;
dO=0;
for (cols=0; cols<3; cols++)
{
if(arr[rows][cols]==X)
r++;
if(arr[rows][cols]==O)
ro++;
if(arr[cols][rows]==X)
c++;
if(arr[cols][rows]==O)
co++;
if(arr[cols][cols]==X)
d++;
if(arr[cols][cols]==O)
dO++;
if (ro==3 || co==3 || dO==3)
game=2;

}
}
if (arr[0][2]==X && arr[1][1]==X && arr[2][0]==X)
d=3;
if (arr[0][2]==O && arr[1][1]==O && arr[2][0]==O)
game=2;
if (r==3 || c==3 || d==3)
game=no;
return game;
}


void counteratk (char arr[][3], char turn)
{
int a=0,b=0,game;
for (a=0; a<3; a++)
for (b=0; b<3; b++)
if (arr[a][b]==' ' && turn==O)
{
arr[a][b]=O;
turn=X;
}
progress(arr);
}

/* This function displays the progress and the status of the board acording to the user input.
It has been made to make as the UI friendly . */
void progress (char arr[][3])
{
cout << " _________________ ";
cout << "| | | | ";
cout << "| " << x[0][0] << " | " << arr[0][1] << " | " << arr[0][2] <<
" | ";
cout << "|_____|_____|_____| ";
cout << "| | | | ";
cout << "| " << arr[1][0] << " | " << arr[1][1] << " | " << arr[1][2] <<
" | ";
cout << "|_____|_____|_____| ";
cout << "| | | | ";
cout << "| " << arr[2][0] << " | " << arr[2][1] << " | " << arr[2][2] <<
" | ";
cout << "|_____|_____|_____| ";

}