Write a program that simluates a game of dice. In this game, players take alternate turns
rolling two dice. On each turn, they record the sum of the two dice and add this to their
total. If a player rolls a doublet (both dice have the same value), then the player gets to
roll again. However, if the doublet is “snake eyes” (both dice have a value of 1) or “box
cars” (both dice have a value of 6), then the player loses their next turn instead. The first
player to reach a total of 75 will win.
For games to 20, the output should be as follow (note: no user input is required):
Example 1:
Player 1 rolls a 3 and a 3
Player 1 now has 6
Player 1 gets to roll again
Player 1 rolls a 5 and a 1
Player 1 now has 12
Player 2 rolls a 5 and a 1
Player 2 now has 6
Player 1 rolls a 5 and a 6
Player 1 now has 23
Player 1 wins with a total of 23
Example 2:
Player 1 rolls a 4 and a 6
Player 1 now has 10
Player 2 rolls a 4 and a 1
Player 2 now has 5
Player 1 rolls a 2 and a 5
Player 1 now has 17
Player 2 rolls a 6 and a 3
Player 2 now has 14
Player 1 rolls a 1 and a 1
Player 1 now has 19
Player 1 loses a turn
Player 2 rolls a 1 and a 2
Player 2 now has 17
Player 2 rolls a 3 and a 5
Player 2 now has 25
Player 2 wins with a total of 25
Note 1: No rolls should occur after a player reaches the winning score (even if they
rolled a doublet).
Please note that this is an assignment for school and I do not want to publicly post my code online..but I don't mind PMing/emailing a user(s). I get everything except for the part of how to alternate it between the two different players. For example, I have two dice randomly generating:
dice1 = (int)(Math.random() * 6) + 1;
dice2 = (int)(Math.random() * 6) + 1;
Then I have what is displayed below. However I don't know how to make it so it alternates for the two players. I also have booleans for "player one's turn, when that player loses a turn and when player two loses a turn". I also know the conditions for which the program should run (while loop) and in an if, else-if I have "doublets" and "snake eyes" defiend respectively.
total1 = dice1 + dice2;
total2 = dice1 + dice2;
sum1 = total1 + total2;
sum2 = total1+total2;