Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 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. System.out.println("Create Password: ");
  72. System.out.println("");
  73. }
  74.  
  75. private static void login() {
  76. System.out.println("Enter Username: ");
  77. System.out.println("Enter Password: ");
  78. System.out.println("");
  79.  
  80. for (int r = 1; r < 6; r++) {
  81. System.out.println("-------------Round " + r + "-------------");
  82. System.out.println("");
  83. System.out.println("Player 1: Enter any key to roll the dice");
  84. x = s.nextLine();
  85. int dice1 = Dice();
  86. System.out.println("Dice one: " + dice1);
  87. int dice2 = Dice();
  88. System.out.println("Dice two: " + dice2);
  89. int dice3 = 0;
  90. if (dice1 == dice2) {
  91. dice3 = Dice();
  92. System.out.println("Dice three: " + dice3);
  93. }
  94. int total = dice1 + dice2 + dice3;
  95. player1 = total + player1;
  96. if (player1 % 2 == 1) {
  97. player1 = player1 - 5;
  98. System.out.println("Player 1 TOTAL: " + player1);
  99. if (player1 < 0) {
  100. player1 = 0;
  101. System.out.println("Player 1 TOTAL: " + player1);
  102. }
  103. } else {
  104. player1 = player1 + 10;
  105. System.out.println("Player 1 TOTAL: " + player1);
  106. }
  107.  
  108. System.out.println("-------------------X-------------------");
  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 TOTAL: " + player2);
  127. if (player2 < 0) {
  128. player2 = 0;
  129. System.out.println("Player 2 TOTAL: " + player2);
  130. }
  131. } else {
  132. player2 = player2 + 10;
  133. System.out.println("Player 2 TOTAL: " + player2);
  134. }
  135.  
  136. }
  137. System.out.println("--------------------------------------");
  138. System.out.println("| Player 1 score = " + player1 + " |");
  139. System.out.println("--------------------------------------");
  140. System.out.println("| Player 2 score = " + player2 + " |");
  141. if (player1 > player2) {
  142. System.out.println("");
  143. System.out.println("THE WINNER IS: PLAYER 1");
  144. System.out.println("");
  145. } else {
  146. System.out.println("THE WINNER IS: PLAYER 2");
  147. }
  148. System.out.println("");
  149. if (player1 == player2) {
  150. sudden();
  151. }
  152. }
  153.  
  154. private static void hiscores() {
  155. System.out.println("Hi-Scores: ");
  156. System.out.println("");
  157. System.out.println("1. ");
  158. System.out.println("2. ");
  159. System.out.println("3. ");
  160. System.out.println("4. ");
  161. System.out.println("5. ");
  162. System.out.println("");
  163. }
  164.  
  165. private static void exit() {
  166. }
  167.  
  168. private static int Dice() {
  169. return (rand.nextInt(6) + 1);
  170. }
  171.  
  172. private static void sudden() {
  173. System.out.println("------------!Sudden Death!------------");
  174. while (player1 == player2) {
  175. System.out.println("Player 1: Enter any key to roll the dice");
  176. x = s.nextLine();
  177. int dice4 = Dice();
  178. System.out.println("Player 1 Score: " + dice4);
  179. System.out.println("--------------------------------------");
  180. System.out.println("Player 2: Enter any key to roll the dice");
  181. y = s.nextLine();
  182. dice4 = Dice();
  183. System.out.println("Player 2 Score: " + dice4);
  184. if (player1 == player2) {
  185. System.out.println("The Winner is: Player 1");
  186. } else {
  187. System.out.println("The Winner is: Player 2");
  188. }
  189. }
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement