Write a program that allows one to play a dice game against the computer. Here a
ID: 3710387 • Letter: W
Question
Write a program that allows one to play a dice game against the computer. Here are the rules: A roll of 3 dice scores as follows: Dice Points 3 one’s 1000 3 of any other number 100 X the number (Ex: 3 two’s would be 200 points) 1 one 100 2 one’s 200 1 five 50 2 fives 100 The higher total at the end of 3 rounds determines the winner. A tie is possible. The form should contain a button labeled “Display rules” to display the rules of the game in a message box. For each round use a random number generator to generate 3 random numbers. Create an int function that has 3 arguments for each of the 3 random numbers and returns the score based on the 3 arguments. Use labels to display the results of each round. The final total at the end of 3 rounds should be displayed. A label should be used to display one of the phrases: “You win!”, “Computer wins!”, or “It’s a tie!”. The form should contain Play Game, Continue, and Reset buttons. The Play Game button should Display the rules of the game in a message box. The Continue button should simulate a roll of the dice for both the player and the computer. The Reset button should clear the screen. Use the Enabled property of buttons to gray them out by changing the value to False and back to True when appropriate. write a program in c#
Explanation / Answer
/*The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: If the player rolls a 2-6 then he can either: — ROLL AGAIN or — HOLD. At this point the sum of all rolls made this turn is added to the player’s total score and it becomes the other player’s turn. If the player rolls a 1 then the player loses his turn. He gets no new points and it becomes the opponent’s turn. If a player reaches 100 or more points after holding then the player wins. Write a program that plays the game of Pig, where one player is a human and the other is the computer. Allow the human to input “r” to roll again or “h” to hold. The computer program should play according to the following rule: Keep rolling on the computer's turn until it has accumulated 20 or more points, then hold. Of course, if the computer wins or rolls a 1 then the turn ends immediately. Allow the human to roll first. Write your program using at least two functions: int humanTurn(int humanTotalScore); int computerTurn(int computerTotalScore); These functions should perform the necessary logic to handle a single turn for either the computer or the human. The input parameter is the total score for the human or computer. The functions should return the turn total to be added to the total score upon completion of the turn. For example, if the human rolls a 3 and 6 and then holds, then humanTurn should return 9. However, if the human rolls a 3 and 6 and then a 1, then the function should return 0.*/ #include #include #include using std::cout; using std::cin; using std::endl; int dieRoll(); int humanTurn(int); int computerTurn(int); int main() { int humanTotalScore = 0, computerTotalScore = 0; srand(time(NULL)); //set a different seed for rand() every time to get different game outputs //loop to keep playing until someone scores 100+ do { humanTotalScore = humanTotalScore + humanTurn(humanTotalScore); //add the score from a new turn to the running total coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.