Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class DiceGame
  2.  
  3. {
  4.  
  5. static int diceX(int minX, int maxX)
  6.  
  7. {
  8.  
  9. int x = (int)(Math.random() * (((maxX + 1) - (minX)) + 1));
  10.  
  11.  
  12.  
  13. return x;
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. }
  22.  
  23.  
  24.  
  25.  
  26.  
  27. static int diceY(int minY, int maxY)
  28.  
  29. {
  30.  
  31. int y = (int)(Math.random() * (((maxY + 1) - (minY)) + 1));
  32.  
  33.  
  34.  
  35. return y;
  36.  
  37.  
  38.  
  39.  
  40.  
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. public static void main(String [] args)
  49.  
  50. {
  51.  
  52.  
  53. System.out.println("Would you like to play? (y/n) ");
  54.  
  55. String responseLine = Console.readString();
  56.  
  57. char response = responseLine.charAt(0);
  58. if(response == 'y')
  59. {
  60. System.out.println("Dice1 rolled " + diceX(1, 6));
  61. System.out.println("Dice2 rolled " + diceY(1, 6));
  62.  
  63. System.out.println((diceX(1, 6) + diceY(1, 6)));
  64.  
  65. int x = diceX(1, 6);
  66. int y = diceY(1, 6);
  67. int s = x + y;
  68.  
  69.  
  70. if((s == 2)) // (s == 3) // (s == 11) // (s == 12))
  71.  
  72. {
  73.  
  74. System.out.println("Score: " + s);
  75.  
  76.  
  77. System.out.println("You win");
  78.  
  79. }
  80.  
  81.  
  82.  
  83. if(s == 7)
  84.  
  85. {
  86.  
  87. System.out.println("Score: " + s);
  88.  
  89.  
  90. System.out.println("You Lose");
  91.  
  92. }
  93.  
  94.  
  95. }
  96.  
  97. if(response == 'n')
  98. {
  99. ;
  100. }
  101.  
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement