Question
MUST BE IN C++. Write a program named PigDice.cppthat plays the game Pig. Pig is a two-player game where the players take turns repeatedly rolling
MUST BE IN C++.
Write a program named PigDice.cppthat plays the game Pig. Pig is a two-player game where the players take turns repeatedly rolling a singlesided die; a player repeatedly rolls the die until one of two events occurs. Either the person chooses to stop rolling, in which case the sum of that players rolls are added to his/her total points; or if the player rolls a 1 at any time, all points for that turn are lost and the turn ends immediately. The first player to reach a score of at least 50 points wins. Additional Requirements: 1. Use the C++ Style Guide to format the code you hand in for this assignment. It is on Canvas under Course Documents.
Here what I have
// Global constants enum class Player { ONE, TWO }; // two player game. const unsigned int GAME_LIMIT = 50; // First player to this value wins.
// function prototypes unsigned int roll(); // simulates rolling one die. unsigned int play( Player player ); // models one player's turn. void reportTotal( Player player, unsigned int score ); // current total. void printWinner( unsigned int player1_total, // Game over, man! unsigned int player2_total );
using namespace std;
// main controls the game, allowing the players to take turns. // main also determines when the game is over. int main() { unsigned int player1_total = 0; unsigned int player2_total = 0;
while ( player1_total < GAME_LIMIT && player2_total < GAME_LIMIT ) { player1_total += play( Player::ONE ); reportTotal( Player::ONE, player1_total );
// if player_1 has won the game, player2 doesn't get another turn. if ( player1_total < GAME_LIMIT ) { player2_total += play( Player::TWO ); reportTotal( Player::TWO, player2_total ); } }
// first person to GAME_LIMIT wins. printWinner(player1_total, player2_total ); // needed in Visual Studio so the console doesn't disappear. system("pause"); }
// simulates rolling one die. unsigned int roll() { // We use the new random facilities of C++11 // They are static so that they are only instantiated once. static default_random_engine engine(static_cast
return randomInt(engine); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started