You will create the Die, LoadedDie, and Game classes. You will use them in the s
ID: 3663045 • Letter: Y
Question
You will create the Die, LoadedDie, and Game classes. You will use them in the simply dice rolling game. •
Die class- it requires an integer N that is the number of sides and returns a random integer between 1 and N. •
LoadedDie class- it inherits the behavior and elements of Die, but the number it returns is biased such that the average of rolls is higher than for Die •
Game class- it will implement the simple dice-rolling game. The user will specify the number of sides on the dice used by each “player”. They do not need to be the same size. The user will indicate if either or both “players” are using loaded dice. The user will also enter the number of rounds in the game. The Game class will create the necessary objects, play the game, and display the results to the user. The output should indicate the size of die used for each player, if it was the loaded die, and the final score.
Explanation / Answer
Answer:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
int gamescore1=0;
int gamescore2=0;
int temperoryscore=0;
int playdice=0;
int chance =1;
char characterdata = 'y';
char player;
bool lastchance = false;
bool lastPlay = false;
srand(time(NULL));
cout << "Do you want to play against a player (p) if yes press p.Thank you :) : ";
cin >> player;
do {
while (characterdata == 'y'){
cout << "Player " << chance << ": Your Turn" << endl;
playdice = rand()%6 + 1;
cout << "playdice :" << playdice << endl;
if (playdice != 1 ){
temperoryscore = temperoryscore + playdice;
if (player == 'p'){
cout << "Your current score is : " << temperoryscore << endl << "Would you like to continue (y/n)?: "<< endl;
cin >> characterdata;
}else if (player == 'b' && chance == 2){
if((rand()%2 + 1) == 1){
characterdata = 'y';
}else if ((rand()%2 + 1) == 2){
cout << "Bot is ending turn..." << endl;
characterdata = 'n';
}
}
}else if (playdice == 1){
temperoryscore = 0;
cout << "Sorry, your score is 0 and you must end your turn." << endl;
characterdata = 'n';
}
}
if (chance == 1){
gamescore1 = gamescore1 + temperoryscore;
temperoryscore = 0;
chance = 2;
}else if (chance == 2){
gamescore2 = gamescore2 + temperoryscore;
temperoryscore = 0;
chance = 1;
}
cout <<endl<< "Score [Player: " << gamescore1 << " Player2: " << gamescore2 <<"]"<< endl <<endl;
characterdata = 'y';
if (gamescore1 >= 100 || gamescore2 >= 100){
if (lastchance == true){
lastPlay = true;
}
if (lastchance == false){
lastchance = true;
if (gamescore1 >= 100){
cout << "Player1 is winning! Player2, you have one last chance to take the game in !!!!!!!!" << endl;
}else if (gamescore2 >= 100){
cout << "Player2 is winning! Player1, you have last chance to take the game in !!!!!!!!" << endl;
}
}
}
}while (lastPlay == false);
if (gamescore1 > gamescore2){
cout << endl << " Player1, you won the game!" << endl << endl;
}else if (gamescore1 < gamescore2){
cout << endl << "Player2, you won the game!" << endl << endl;
}else if (gamescore1 == gamescore2){
cout << endl << "Tie Break !!!!!!!!! Player1 and Player2, you have tied the game!" << endl << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.