Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class DiceGame {
- public static void main(String[] args) {
- int p1Score = 0;
- int p2Score = 0;
- int die1;
- int die2;
- int die3;
- int die4;
- do {
- die1 = new Random().nextInt(6) + 1;
- die2 = new Random().nextInt(6) + 1;
- System.out.println("Player 1 rolls a " + die1 + " and a " + die2);
- p1Score = p1Score + die1 + die2;
- System.out.println("Player 1 now has " + p1Score);
- if (die1 == die2) {
- System.out.println("Player 1 gets to roll again.");
- die1 = new Random().nextInt(6) + 1;
- die2 = new Random().nextInt(6) + 1;
- System.out.println("Player 1 rolls a " + die1 + " and a " + die2);
- p1Score = p1Score + die1 + die2;
- System.out.println("Player 1 now has " + p1Score);
- }
- die3 = new Random().nextInt(6) + 1;
- die4 = new Random().nextInt(6) + 1;
- System.out.println("Player 2 rolls a " + die3 + " and a " + die4);
- p2Score = p2Score + die3 + die4;
- System.out.println("Player 2 now has " + p2Score);
- if (die3 == die4) {
- System.out.println("Player 2 gets to roll again.");
- die3 = new Random().nextInt(6) + 1;
- die4 = new Random().nextInt(6) + 1;
- System.out.println("Player 2 rolls a " + die3 + " and a " + die4);
- p2Score = p2Score + die3 + die4;
- System.out.println("Player 2 now has " +p2Score);
- }
- } while (p1Score < 75 || p2Score < 75);
- if (p1Score > 75) {
- System.out.printf("Player 1 has won with a score of " + p1Score);
- } else if(p2Score > 75) {
- System.out.printf("Player 2 has won with a score of " + p2Score);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement