Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.util.Random;
  2. public class DiceGame {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. int p1Score = 0;
  7. int p2Score = 0;
  8. int die1;
  9. int die2;
  10. int die3;
  11. int die4;
  12.  
  13.  
  14. do {
  15. die1 = new Random().nextInt(6) + 1;
  16. die2 = new Random().nextInt(6) + 1;
  17.  
  18. System.out.println("Player 1 rolls a " + die1 + " and a " + die2);
  19.  
  20. p1Score = p1Score + die1 + die2;
  21. System.out.println("Player 1 now has " + p1Score);
  22.  
  23. if (die1 == die2) {
  24. System.out.println("Player 1 gets to roll again.");
  25. die1 = new Random().nextInt(6) + 1;
  26. die2 = new Random().nextInt(6) + 1;
  27. System.out.println("Player 1 rolls a " + die1 + " and a " + die2);
  28.  
  29. p1Score = p1Score + die1 + die2;
  30. System.out.println("Player 1 now has " + p1Score);
  31. }
  32.  
  33. die3 = new Random().nextInt(6) + 1;
  34. die4 = new Random().nextInt(6) + 1;
  35.  
  36. System.out.println("Player 2 rolls a " + die3 + " and a " + die4);
  37.  
  38. p2Score = p2Score + die3 + die4;
  39. System.out.println("Player 2 now has " + p2Score);
  40.  
  41. if (die3 == die4) {
  42. System.out.println("Player 2 gets to roll again.");
  43. die3 = new Random().nextInt(6) + 1;
  44. die4 = new Random().nextInt(6) + 1;
  45. System.out.println("Player 2 rolls a " + die3 + " and a " + die4);
  46.  
  47. p2Score = p2Score + die3 + die4;
  48. System.out.println("Player 2 now has " +p2Score);
  49. }
  50.  
  51. } while (p1Score < 75 || p2Score < 75);
  52.  
  53.  
  54. if (p1Score > 75) {
  55. System.out.printf("Player 1 has won with a score of " + p1Score);
  56.  
  57. } else if(p2Score > 75) {
  58. System.out.printf("Player 2 has won with a score of " + p2Score);
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement