C++ Programming INTRODUCTION: Play sorry with two die, and one peg. Move your pi
ID: 3837041 • Letter: C
Question
C++ Programming INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first. But rolling certain numbers will change the pace of the game.
ASSIGNMENT: Sorry Game
1.To play “Sorry”, you’ll need to create up to Four players.
Prompt the user for the number of players (2-4).
2. Create two die for the players to roll.
3. Create an Array to be used to track the player’s positions on the playing board.
4. The playing board has 50 spaces (with 50 being the winning space).
5. 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
6. A player must roll a double to start.
7. 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.
8. A player must roll an EXACT number to enter the winning space.
9. Use a random Generator to “roll” the dice, the user must press enter to roll.
10. Depict the players’ positions on the screen after each round.
11. Once a player finishes, create a winning message announcing the winner.
12. Then ask the user if they would like to play again.
13. You must use at least three functions. Some function examples could be:
Roll dice, check for other player (when moving), display board.
14. Display the status/location of the players between sets of rolls.
15. 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)
16. If a player rolls a double, they’ll get another roll (Extra Credit).
17. If a player rolls two doubles in a row, they Start Over (Extra Credit).
I need a programming in c++ lanuage.
Screen shots depicting the program in use.
Explanation / Answer
#include<iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
using namespace std
int RandomNumber()
{
srand (time(NULL));
return rand() % 12 + 2;
}
bool CheckWinner(int i)
{
return (i==50);
}
int main()
{
int noOfPlayer=0;
cout << "Enter number of Player" ;
cin >> noOfPlayer;
while(noOfPlayer < 2 || noOfPlayer > 4)
{
cout << "Please enter valid number of player" << endl;
cin >> noOfPlayer;
}
int spaces[50];
int playerPos[noOfPlayer];
for(int i=0;i<noOfPlayer;i++)
playerPos[i] = 0;
bool win = false;
int winner;
while(!win)
{
for(int j=0;j<noOfPlayer;j++)
{
cout << "Player " << j+1 << " turn move dice " << endl;
int num = RandomNumber();
switch(num)
{
case 2:
{
if(playerPos[j]+2 <= 50)
playerPos[j] += 2;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 3:
{
if(playerPos[j]+3 <= 50)
playerPos[j] += 3;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 4:
{
if(playerPos[j]-1 >=0)
playerPos[j] -= 1;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 5:
{
if(playerPos[j]+25 <= 50)
playerPos[j] += 5;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 6:
{
if(playerPos[j]+6 <= 50)
playerPos[j] += 6;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 7:
{
int k=0;
while(k < noOfPlayer)
{
if(k != j && playerPos[k] > playerPos[j])
playerPos[j] = playerPos[k];
k++;
}
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 8:
{
if(playerPos[j]+8 <= 50)
playerPos[j] += 8;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 9:
{
if(playerPos[j]+9 <= 50)
playerPos[j] += 9;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 10:
{
if(playerPos[j]+10 <= 50)
playerPos[j] += 10;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 11:
{
int k=0;
while(k < noOfPlayer)
{
if(k != j && playerPos[k] < playerPos[j])
playerPos[j] = playerPos[k];
k++;
}
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
case 12:
{
playerPos[j] = 0;
if(CheckWinner(playerPos[j]))
{
win = true;
winner = j+1;
}
break;
}
}
}
}
cout << " Winner is " << winner+1 ;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.