Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package nea;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author 9400
  14. */
  15. public class NEA {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. static int player1 = 0;
  21. static int player2 = 0;
  22. static Random rand = new Random();
  23. static String x;
  24. static String y;
  25. static Scanner s = new Scanner(System.in);
  26. static char User1;
  27. static char User2;
  28.  
  29. public static void main(String[] args) {
  30. // TODO code application logic here
  31.  
  32. int choice;
  33. do {
  34. System.out.println("Dice Game!");
  35. System.out.println("____________________");
  36. System.out.println("Main Menu: ");
  37. System.out.println("1 > Register");
  38. System.out.println("2 > Log-in & Play");
  39. System.out.println("3 > Hi-Scores");
  40. System.out.println("4 > Exit Game");
  41. System.out.println("____________________");
  42. System.out.println("Choose an option: 1-4");
  43. System.out.println("");
  44. choice = s.nextInt();
  45. s.skip("\n");
  46.  
  47. switch (choice) {
  48. case 1:
  49. register();
  50. break;
  51. case 2:
  52. login();
  53. break;
  54. case 3:
  55. hiscores();
  56. break;
  57. case 4:
  58. System.out.println("Goodbye");
  59. System.exit(0);
  60. break;
  61. default:
  62. System.out.println("Invalid Option. Try Again");
  63. System.out.println("");
  64. break;
  65. }
  66. } while (choice != 4);
  67. }
  68.  
  69. private static void register() {
  70. System.out.println("Create Username: ");
  71.  
  72. System.out.println("Create Password: ");
  73. System.out.println("");
  74. }
  75.  
  76. private static void login() {
  77. System.out.println("Enter Username: ");
  78. System.out.println("Enter Password: ");
  79. System.out.println("");
  80.  
  81. for (int r = 1; r < 6; r++) {
  82. System.out.println("-------------Round " + r + "-------------");
  83. System.out.println("");
  84. System.out.println("Player 1: Enter any key to roll the dice");
  85. x = s.nextLine();
  86. int dice1 = Dice();
  87. System.out.println("Dice one: " + dice1);
  88. int dice2 = Dice();
  89. System.out.println("Dice two: " + dice2);
  90. int dice3 = 0;
  91. if (dice1 == dice2) {
  92. dice3 = Dice();
  93. System.out.println("Dice three: " + dice3);
  94. }
  95. int total = dice1 + dice2 + dice3;
  96. player1 = total + player1;
  97. if (player1 % 2 == 1) {
  98. player1 = player1 - 5;
  99. System.out.println("Player 1 score: " + player1);
  100. } else {
  101. player1 = player1 + 10;
  102. }
  103. if (player1 < 0) {
  104. player1 = 0;
  105. System.out.println(player1);
  106. }
  107. System.out.println("Player 1 score: " + player1);
  108. System.out.println("");
  109.  
  110. System.out.println("Player 2: Enter any key to roll the dice");
  111. y = s.nextLine();
  112. dice1 = Dice();
  113. System.out.println("Dice one: " + dice1);
  114. dice2 = Dice();
  115. System.out.println("Dice two: " + dice2);
  116. dice3 = 0;
  117. if (dice1 == dice2) {
  118. dice3 = Dice();
  119. System.out.println("Dice three: " + dice3);
  120. }
  121. total = dice1 + dice2 + dice3;
  122. player2 = total + player2;
  123.  
  124. if (player2 % 2 == 1) {
  125. player2 = player2 - 5;
  126. System.out.println("Player 2 score: " + player2);
  127. } else {
  128. player2 = player2 + 10;
  129. }
  130. if (player2 < 0) {
  131. player2 = 0;
  132. System.out.println(player2);
  133. }
  134. System.out.println("Player 2 score: " + player2);
  135. System.out.println("");
  136.  
  137. if (player1>player2) {
  138. System.out.println("The Winner is: Player 1");
  139. System.out.println("");
  140. }
  141. else
  142. System.out.println("The Winner is: Player 2");
  143. System.out.println("");
  144. }
  145. if (player1==player2) {
  146. System.out.println("-------------Sudden Death-------------");
  147. }
  148. }
  149.  
  150. private static void hiscores() {
  151. System.out.println("Hi-Scores: ");
  152. System.out.println("");
  153. System.out.println("1. ");
  154. System.out.println("2. ");
  155. System.out.println("3. ");
  156. System.out.println("4. ");
  157. System.out.println("5. ");
  158. System.out.println("");
  159. }
  160.  
  161. private static void exit() {
  162. }
  163.  
  164. private static int Dice() {
  165. return (rand.nextInt(6) + 1);
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement