Only post comment if you have full answer. Do not spam or advertise!!! On each t
ID: 3541254 • Letter: O
Question
Only post comment if you have full answer. Do not spam or advertise!!!
On each turn, the player rolls twice. First rolling a 6-sized "turn die" which determines the size of a larger "play die" for that turn. The higher the roll on the turn die, the better chance of getting a larger play die, thus increasing the chance of getting a higher roll on the play die. Two players are trying to reach the top of Dorado Mountain and win the gold. They face obstacles along the way! Level 1 is 1-50, level 2 is 50-100, level 3 is 100-150. Gold level is from 150-200. The first player to 200 reaches Dorado mountain wins. In each turn, player will roll the six sided turn die to determine their next roll as follows: Turn Die Roll Play Die Size 1 10 2 15 3 20 4 25 5 30 6 35 Thus if the player's turn die roll is a 1, the player then rolls the 10-sided play die. Etc. The program should ask for the names of the two players then the first name entered will go first. The program should clearly tell the players what they are rolling: the six sided turn die first, then the size of the corresponding play die, and their rolls for each. If a player rolls the same number twice on consequtive play dice, or if his play die roll equals his previous play die roll times three, the program will output that he has run into a dragon and lose ten points of his score. If a player's play die roll is greater than his previous play die roll, the program will output that a friendly gryphon has given him a boost and he gains ten points, added to his score. The display should include: player, rolls, and levels at each turn. I.e. When a score of 50 is reached, the program should output to the screen that the player has reached level 2. When the player reaches 100, the program should output to the screen that the player has reached level 3.. .etc. Play should continue until player reaches the top of the mountain. The player who reaches 200 first wins the game.Explanation / Answer
Here you go, not sure if you want an indication of what turn it is when or a pause between each turn. The game plays all the way through automatically and ends once a player hits 200+. If there is anything you don't understand just ask on comments. I'll provide a Ideone link at the end also just incase Chegg ruins any part of the code when percent signs and rand are involved(html code problem).
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int turnDie()
{
return rand() %6+1;
}
int playDie(int TD)
{
switch(TD){
case 1:
cout << "A Dice of size 10 is being rolled.." << endl;
return rand()% 10+1;
break;
case 2:
cout << "A Dice of size 15 is being rolled.." << endl;
return rand()% 15+1;
break;
case 3:
cout << "A Dice of size 20 is being rolled.." << endl;
return rand()% 20+1;
break;
case 4:
cout << "A Dice of size 25 is being rolled.." << endl;
return rand()% 25+1;
break;
case 5:
cout << "A Dice of size 30 is being rolled.." << endl;
return rand()% 30+1;
break;
case 6:
cout << "A Dice of size 35 is being rolled.." << endl;
return rand()% 35+1;
break;
default:
cout << "Uh oh... Something went wrong, you are never to reach here!" << endl;
break;
}
}
void displayLvl(int total)
{
if(total > 0 && total < 50)
cout << " is on Level 1." << endl << endl;
else if(total > 49 && total < 100)
cout << " is on Level 2." << endl << endl;
else if(total > 99 && total < 150)
cout << " is on Level 3." << endl << endl;
else if(total > 149 && total < 200)
cout << " is on Gold Level." << endl << endl;
}
int main()
{
srand((unsigned)time(NULL));
string p1Name, p2Name;
int p1TD, p2TD, p1PD, p2PD, p1Total = 0, p2Total = 0, p1Prev = 0, p2Prev = 0;
cout << "Enter player 1 name: ";
cin >> p1Name;
cout << "Enter player 2 name: ";
cin >> p2Name;
while(1){
//player1's turn
cout << p1Name << "'s turn" << endl;
p1TD = turnDie();
cout << "Turn Die roll: " << p1TD << endl;
p1PD = playDie(p1TD);
cout << "Play Die roll: " << p1PD << endl;
//penalty check
if(p1PD == p1Prev || p1PD == (p1PD*3)){
cout << p1Name << " has ran into a dragon causing a loss of 10 points." << endl;
p1Total -= 10;
}
//reward check
else if(p1PD > p1Prev && p1Prev != 0){
cout << p1Name << " has been given a boost by a friendly Gryphon resulting in a gain of 10 points." << endl;
p1Total += 10;
}
p1Prev = p1PD;
p1Total += p1PD;
//winner check
if(p1Total >= 200){
cout << endl << p1Name << " has reached the top of Dorado mountain and has won!" << endl << endl;
cout << "Final Scores:" << endl << p1Name << ": " << p1Total << endl << p2Name << ": " << p2Total << endl;
break;
}
//level display
cout << p1Name;
displayLvl(p1Total);
//player2's turn
cout << p2Name << "'s turn" << endl;
p2TD = turnDie();
cout << "Turn Die roll: " << p2TD << endl;
p2PD = playDie(p1TD);
cout << "Play Die roll: " << p2PD << endl;
if(p2PD == p2Prev || p2PD == (p2PD*3)){
cout << p2Name << " has ran into a dragon causing a loss of 10 points." << endl;
p2Total -= 10;
}
//reward check
else if(p2PD > p2Prev && p2Prev != 0){
cout << p2Name << " has been given a boost by a friendly Gryphon resulting in a gain of 10 points." << endl;
p2Total += 10;
}
p2Prev = p2PD;
p2Total += p2PD;
//winner check
if(p2Total >= 200){
cout << endl << p2Name << " has reached the top of Dorado mountain and has won!" << endl << endl;
cout << "Final Scores:" << endl << p1Name << ": " << p1Total << endl << p2Name << ": " << p2Total << endl;
break;
}
//level display
cout << p2Name;
displayLvl(p2Total);
}
return 0;
}
Here is the exact same code on Ideone just incase: http://ideone.com/Lbs1cT
They should be the same, if they aren't then Chegg probably messed up anywhere there is a percent sign followed by numbers
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.