In this assignment, you are to write a program to play a game of Devil\'s Dice w
ID: 3563996 • Letter: I
Question
In this assignment, you are to write a program to play a game of Devil's Dice with the user.
Devil's Dice is a popular IOS game developed by Soft Dorothy, LLC that is based on the folk game "Pig".
You can learn more about Devil's Dice at https://itunes.apple.com/us/app/the-devils-dice/id473597789?mt=8 (Links to an external site.)
and about Pig at http://en.wikipedia.org/wiki/Pig_(dice_game) (Links to an external site.).
The rules of the games as described on Wikipedia are: Each turn, a player repeatedly rolls a die (Links to an external site.) until either a 1 is rolled or the player decides to "hold":- If the player rolls a 1, they score nothing and it becomes the next player's turn. If the player rolls any other number, it is added to their turn total and the player's turn continues. If a player chooses to "hold", their turn total is added to their score, and it becomes the next player's turn. The first player to score 100 or more points wins.
For example, the first player, Ann, begins a turn with a roll of 5. Ann could hold and score 5 points, but chooses to roll again. Ann rolls a 2, and could hold with a turn total of 7 points, but chooses to roll again. Ann rolls a 1, and must end her turn without scoring. The next player, Bob, rolls the sequence 4-5-3-5-5, after which he chooses to hold, and adds his turn total of 22 points to his score. In this assignment, you need to re-do the devil's dice game, but use text output statements to emulate the screen in the IOS game.
In your code, you must: Use at least one function devoted to printing out the screen. Ask the user after the game if he/she wants to play again. Use a file to keep track of the wins and losses, and print the results at the end of each game. I've captured a few screenshots to show you what I am looking for, but because they don't show up well in Canvas, I've left it as a text file entitled "ddScreenShots.txt" in the main cs1400 Google Drive directory for the class. Turn in: your .cpp file.
Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
int die;
int myScore = 95;
int devilScore = 95;
int turnScore = 0;
int myScoretotal = myScore += turnScore;
int devilScoretotal = devilScore += turnScore;
char choice;
bool change = false;
cout << "Welcome to Devil's Dice! Please select from the following menu: ";
while(change == false){ //&& devilScoretotal < 100 && myScoretotal < 100){
cout << " Roll [r], Pass [p], or Quit [q].";
cin >> choice;
if(choice == 'r'){
die=(rand() % 6 + 1); //Number generator for die
if(die > 1){
cout << "You rolled a " << die << "." << endl;
turnScore += die;
cout << "You will add " << turnScore << " points if you pass now. ";}
else{
cout << "You rolled a 1. You lose your points and your turn ends." << endl;
change = true;
turnScore = 0;
}
}
if(choice == 'p')
{myScore += turnScore;
cout << "Your score is now " << myScore << "." << endl;
turnScore = 0;
change = true; } //needs to go to Devil now
if(choice == 'q')
{cout << " Thanks for playing! ";
return 0; }
else if(choice > 'r' || choice < 'p')
{cout << "Please select from the choices listed."; }
}
while(change == true){// && devilScoretotal < 100 && myScoretotal < 100){ //The Devil's actions
if(myScore > devilScore && turnScore < 17 || devilScore > myScore && turnScore < 12 || devilScore > 84){
choice='r';
cout << "The Devil rolls! " << endl;
if(choice == 'r'){
die=(rand() % 6 + 1); //Number generator for die
if(die > 1){
cout << "The Devil rolls a " << die << "." << endl;
turnScore += die;
}else{
cout << "The Devil rolls a 1. He loses his points and now it's your turn!" << endl;
turnScore = 0;
change = false;
}
}else{
cout << "The Devil chooses to pass. ";
devilScore += turnScore;
choice='p';
turnScore = 0;
cout << "He has " << devilScore << " points. " << endl;
cout << "The Devil now has " << devilScore << " points." << endl;
change = false;
}
}
}
}
Have a look at :
http://stackoverflow.com/questions/19012084/dice-game-pig-in-c
http://sourceforge.net/projects/devildicegold/