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

in c++ You are to create a game where there are two players and a \"board\" cons

ID: 675452 • Letter: I

Question

in c++ You are to create a game where there are two players and a "board" consisting of 20 spaces. The spaces have a sequence of values consisting of 10. 20, 30 .... 190, 200. You are to create a circular list of these spaces - print the values in the list (i.e. should print values from 10 to 200). Both players are starting at the 10 space with 0 points Then each player will roll the pair of dice resulting in a value between 1 and 12 - use a random number generator to generate this number (see below). The players will be moved that many spaces and add the value of that space to their score. Print out the dice roll amount and the value of the space that they land on. After each set of moves (i.e. player 1 and player 2 have moved) print the total scores. The game ends when a player reaches 1000 or more points. Print out which player won the game.

Explanation / Answer

// Example program
#include <iostream>
#include <cstdlib>
#include<ctime>
using namespace std;
int main()
{
int p1=1;
int p2=1;
int s1=0,s2=0;
int roll=1;
srand((unsigned)time(NULL));
int r;
cout<<"10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200"<<' ';
while(s1<1000 && s2<1000)
{
       r = (rand()%12)+1;
       p1 = p1+r;
       if(p1>20)
        p1=p1-20;
        s1 += p1*10;
        cout<<"Player one rolls a "<<r<<" - at space with value "<<p1*10<<' ';
      
         r = (rand()%12)+1;
       p2 = p2+r;
       if(p2>20)
        p2=p2-20;
        s2 += p2*10;
        cout<<"Player two rolls a "<<r<<" - at space with value "<<p2*10<<' ';
      
        cout<<"After roll "<<roll<<" - Player 1 score is "<<s1<<",Player 2 score is "<<s2<<' ';
      
        roll++;
}
if(s1>s2)
{
      cout<<"The winner is Player 1 - Player 1 score is "<<s1<<" to Player 2 score is "<<s2<<' ';
}
else if(s2>s1)
{
      cout<<"The winner is Player 2 - Player 2 score is "<<s2<<" to Player 1 score is "<<s1<<' ';
}
else
{
      cout<<"It's a tie - Player 1 score is "<<s1<<", Player 2 score is "<<s2<<' ';
}
}