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

To play \"Sorry\", you\'ll need to create up to Four players. Prompt the user fo

ID: 3580970 • Letter: T

Question

To play "Sorry", you'll need to create up to Four players. Prompt the user for the number of players (2-4). Create two die for the players to roll. Create an Array to be used to track the player's positions on the playing board. The playing board has 50 spaces (with 50 being the winning space). The dice have special conditions: 2 = Move two spaces 3 = Move three spaces 4 = Move back one space. 5 = Move five spaces. 6 = Move six spaces. 7 = Swap spots with the leading layer/or nothing if player is in lead. 8 = Move Eight spaces. 9 = Move nine spaces. 10 = Move ten spaces. 11 = Swap spots with the last player/or do nothing if player is last. 12 = Start Over A player must roll a double to start. If a player lands on the same space as another, the other player must return to the beginning. Example: If P1 lands on a space where P3 is, P3 would go back to the start. A player must roll an EXACT number to enter the winning space. Use a random Generator to "roll" the dice, the user must press enter to roll. Depict the players' positions on the screen after each round. Once a player finishes, create a winning message announcing the winner. Then ask the user if they would like to play again. You must use at least three functions. Some function examples could be: Roll dice, check for other player (when moving), display board.| Display the status/location of the players between sets of rolls. Depict a Playing Board on the screen and display the Players' position on the board. (Extra Credit) (maybe try using a method to create the board and screen each time a player moves) If a player rolls a double, they'll get another roll (Extra Credit). If a player rolls two doubles in a row, they Start Over (Extra Credit).

Explanation / Answer

   Solution:

   #include <iostream>
   #include <conio>
   #include <string>

   #include <ctime>
   #include <cstdlib>
   #include <windows>

   using namespace std;

   int main()
   {
   clrscr();
   /* Program name: tictactoe.cpp
   /* Author: Twilight Sparkle
   /* To play “Sorry”, you’ll need to create up to Four players. Prompt the user for the number of players (2-4). *
   /* Create two die for the players to roll. *
   /* Create an Array to be used as the playing board, having 50 spaces With 50 being the winning space. *

   int MenuChoice;

   /* Board Variables *
   char Square1('1');
   char Square2('2');
   char Square3('3');
   char Square4('4');
   char Square5('5');
   char Square6('6');
   char Square7('7');
   char Square8('8');
   char Square9('9');

   /* Player Variable *
   int PlayerTurn(1);

   /* Whether the game is over or not in the while loop *
   bool GameOverDecider(true);
   cout << " Would you like to play some TIC-TAC-TOE today=" << endl;
   cout << endl;
   cout << " (1)Game Start(2 players required)" << endl;
   cout << " (2)Quit Game" << endl;
   cout << endl;
   cout << "Choice( 1 or 2)=" << endl;
   cin >> MenuChoice >> endl;
   if (MenuChoice == 1)
   {
   do
   {
   /* Player Variable *
   int PlayerTurn(1);

   /* Whether the game is over or not in the while loop *
   bool GameOverDecider(true);
          
   /* Main Game Board *
   cout << " " << Square1 << " | " << Square2 << " | " << Square3 << endl;
   cout << " -----+-----+-----" << endl;
   cout << " " << Square4 << " | " << Square5 << " | " << Square6 << endl;
   cout << " -----+-----+-----" << endl;
   cout << " " << Square7 << " | " << Square8 << " | " << Square9 << endl;
   cout << " -----+-----+-----" << endl;

   /* Set Player Marker, Player 1 uses X and Player 2 uses O
   char PlayerMarker;
   if (PlayerTurn = 1)
   {
   PlayerMarker = 'X';
   }
   else
   {
   PlayerMarker = 'O';
   }

   /* End of Main Do While Loop *
   }
   while (!GameOverDecider);

   /* End of Menu Choice If Statement *
   }
   else(MenuChoice = = 2)
   {
   cout << "Ok....." << endl;
   }


   void display_playingboard();

   void player_turn();

   bool gameover();

   class TicTacToe
   {
   enum PLAYER
   {
   NONE = 0;
   PLAYER1 = 1, // 'O'
   PLAYER2 = -1, // 'X'
   };

   union
   {
   PLAYER _dim1[9] = {NONE};
   PLAYER _dim2[3][3];
   };

   typedef std : : array<std::string, 2> strarr2_t;
   strarr2_t_name;

   bool_player1_turn;

   inline std : : string get_player_name(std::size_t player)
   {
   std : : string name;

   std : : cout << "Player " << player << " name=" endl;
   if (not (std : : cin >> name).good())
   throw std : : runtime_error("Input error");
   return name;
   }

   public:
   TicTacToe(void) :
   _name{{get_player_name(1u), get_player_name(2u)}},
   _player1_turn(true)
   {
   }
   void display_board()

   {

   cout << "---------------------" << endl;

   cout << " | | " << endl;

   cout << " " << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;

   cout << "_____|_____|_____" << endl;

   cout << " | | " << endl;

   cout << " " << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;

   cout << "_____|_____|_____" << endl;

   cout << " | | " << endl;

   cout << " " << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;

   cout << " | | " << endl;

   }


   void player_turn()

   {

   int choice;

   int row = 0, column = 0;

   if (turn == 'X')

   {

   cout << "Player 1 turn [X]: ";

   }

   else if (turn == 'O')

   {

   cout << "Player 2 turn [O]: ";

   }

   cin >> choice;

   switch (choice)

   {

   case 1: row = 0; column = 0;
   break;

   case 2: row = 0; column = 1;
   break;

   case 3: row = 0; column = 2;
   break;

   case 4: row = 1; column = 0;
   break;

   case 5: row = 1; column = 1;
   break;

   case 6: row = 1; column = 2;
   break;

   case 7: row = 2; column = 0;
   break;

   case 8: row = 2; column = 1;
   break;

   case 9: row = 2; column = 2;
   break;

   default:

   cout << "You didn't enter a correct number! Try again ";

   player_turn();

   }

   if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O')

   {

   board[row][column] = 'X';

   turn = 'O';

   }

   else
   if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O')

   {

   board[row][column] = 'O';

   turn = 'X';

   }

   else

   {

   cout << "The cell you chose is used! Try again ";

   player_turn();

   }


   }
  

bool gameover()

   {

   for (int i = 0; i < 3; i++)       /* Check for a win *

   {

   if ((board[i][0] = = board[i][1] && board[i][1] = = board[i][2]) || (board[0][i] = = board[1][i]
   && board[1][i] = = board[2][i]) || (board[0][0] = = board[1][1]
   && board[1][1] = = board[2][2]) || (board[0][2] = = board[1][1] && board[1][1] == board[2][0]))

   {

   return true;

   }

   }

   for (int i = 0; i < 3; i++)       /* Check for draw
*
   {

   for (int j = 0; j < 3; j++)

   {

   if (board[i][j] != 'X' && board[i][j] != 'O')

   {

   return false;

   }

   }

   }

   draw = true;

   return true;
  
}
   return TicTacToe().loop();
   }


   /* Start the game, asking for each Player for a move *

   /* Bool Variable in order to check if the move is valid *
   bool ValidTurn;
   /* Run a do while loop to check if their hasn't been a square filled in or
   do
   {
   /* Char Variable to get next move *
   char CurrentMove;

   cout << "Player" << PlayerTurn << "'s turn, set move on what square: " << endl;
   cin >> CurrentMove >> endl;
   ValidTurn = true;

   /* If Statment Checking if the move is invalid
   **If the move equals 1-9 and a number, and if no one has marked the space yet
   **Checks Each Square *
   if (CurrentMove == '1' && Square1 == '1')
   {
   Square1 = PlayerMarker;
   }
   else
   if (CurrentMove == '2' && Square1 == '2')
   {
   Square2 = PlayerMarker;
   }
   else
   if (CurrentMove = = '3' && Square1 = = '3')
   {
   Square3 = PlayerMarker;
   }
   else
   if (CurrentMove == '4' && Square1 == '4')
   {
   Square4 = PlayerMarker;
   }
   else
   if (CurrentMove = = '5' && Square1 = = '5')
   {
   Square5 = PlayerMarker;
   }
   else
   if (CurrentMove = = '6' && Square1 = = '6')
   {
   Square6 = PlayerMarker;
   }
   else
   if (CurrentMove = = '7' && Square1 = = '7')
   {
   Square7 = PlayerMarker;
   }
   else
   if (CurrentMove = = '8' && Square1 = = '8')
   {
   Square8 = PlayerMarker;
   }
   else
   if (CurrentMove = = '9' && Square1 = = '9')
   {
   Square9 = PlayerMarker;
   }
   else
   {
   cout << "Invalid Move, make another one:" << endl;
   ValidTurn = false;
   }
   }
   while(!ValidTurn);

   /* GameOverDecider Bool Variable now set to false, showing the game is over *
   GameOverDecider = false;
   /* New Bool variable *
   bool WinGame = true;

   /* Win Condition that's through either square 1, 4, and 7 or 1, 2, and 3 *
   if(Square1 != '1')
   {
   /* 1, 2, and 3 *
   if (Square2 = = Square1 && Square3 = = Square1)
   {
   GameOverDecider = true;
   }
   /* 1, 4, and 7 *
   if (Square4 = = Square1 && Square7 = = Square1)
   {
   GameOverDecider = true;
   }
   }
  
   /* Win Condition that's through either square 3, 6, and 9 or 7, 8, and 9 *
   if(Square1 != '9')
   {
   /* 3, 6, and 9 *

   if (Square3 = = Square9 && Square6 = = Square9)
   {
   GameOverDecider = true;
   }
   /* 7, 8, and 9

   if (Square7 = = Square9 && Square8 = = Square9)
   {
   GameOverDecider = true;
   }
   }

   /* Win Conditions through the middle square, 4 conditions *
          
   if(Square1 != '5')
   {
   /* 1, 5, and 9 *
   if (Square1 = = Square5 && Square9 = = Square5)
   {
   GameOverDecider = true;
   }
   /* 2, 5, and 8 *
   if (Square2 = = Square5 && Square8 = = Square5)
   {
   GameOverDecider = true;
   }
   /* 4, 5, and 6 *
   if (Square4 = = Square5 && Square6 = = Square5)
   {
   GameOverDecider = true;
   }
   /* 3, 5, and 7 *
   if (Square3 = = Square5 && Square7 = = Square5)
   {
   GameOverDecider = true;
   }
   }

   /* Check if their are draws *
   if (Square1 != '1' && Square2 != '2' && Square3 != '3' && Square4 != '4' && Square5 != '5' && Square6 != '6'
   && Square7 != '7' && Square8 != '8' && Square9 != '9' && !GameOverDecider)
   {
   GameOverDecider = true;
   WinGame = false;
   if(GameOverDecider)
   {
   if(WinGame)
   {
   cout << "Player " << PlayerTurn << " totally wins!" << endl;
   }
   /* Print the result board *
   cout << " " << Square1 << " | " << Square2 << " | " << Square3 << endl;
   cout << " -----+-----+-----" << endl;
   cout << " " << Square4 << " | " << Square5 << " | " << Square6 << endl;
   cout << " -----+-----+-----" << endl;
   cout << " " << Square7 << " | " << Square8 << " | " << Square9 << endl;
   cout << " -----+-----+-----" << endl;

   /* Choice to whether to play the game again *

   cout << " Game Over!" << endl;
   cout << " Want to play again?(Y/N)?: ";
   char PlayAgain;
   cin >> PlayAgain;

   /* Clears Board Back to the original numbers *
   if(PlayAgain = 'y')
   {
   GameOverDecider = false;
   Square1 = '1';
   Square2 = '2';
   Square3 = '3';
   Square4 = '4';
   Square5 = '5';
   Square6 = '6';
   Square7 = '7';
   Square8 = '8';
   Square9 = '9';
   }
   PlayerTurn = 1;
   }
   else
   {
   /* If the game is still going on, alternate the players turns *
   if (PlayerTurn = = 1)
   {
   PlayerTurn = 2;
   }
   else
   {
   PlayerTurn = 1;
   }
   }      
   return 0;
   getch();
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote