Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 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.io.BufferedReader;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.util.Arrays;
  13. import java.util.Random;
  14. import java.util.Scanner;
  15.  
  16. /**
  17. *
  18. * @author 9400
  19. */
  20. public class NEA {
  21.  
  22. /**
  23. * @param args the command line arguments
  24. */
  25. static int player1 = 0;
  26. static int player2 = 0;
  27. static Random rand = new Random();
  28. static String x;
  29. static String y;
  30. static Scanner s = new Scanner(System.in);
  31. static char User1;
  32. static char User2;
  33.  
  34. public class General{
  35. int Hiscores;
  36. String username, password;
  37.  
  38. General(int Hiscores, String username, String password){
  39. this.Hiscores = Hiscores;
  40. this.username = username;
  41. this.password = password;
  42. }
  43. }
  44. public static void main(String[] args) {
  45. // TODO code application logic here
  46. fileReader();
  47. int choice;
  48. do {
  49. System.out.println("Dice Game!");
  50. System.out.println("____________________");
  51. System.out.println("Main Menu: ");
  52. System.out.println("1 > Register");
  53. System.out.println("2 > Log-in & Play");
  54. System.out.println("3 > Hi-Scores");
  55. System.out.println("4 > Exit Game");
  56. System.out.println("____________________");
  57. System.out.println("Choose an option: 1-4");
  58. System.out.println("");
  59. choice = s.nextInt();
  60. s.skip("\n");
  61.  
  62. switch (choice) {
  63. case 1:
  64. register();
  65. break;
  66. case 2:
  67. login();
  68. break;
  69. case 3:
  70. hiscores();
  71. break;
  72. case 4:
  73. System.out.println("Goodbye");
  74. fileWriter();
  75. System.exit(0);
  76. break;
  77. default:
  78. System.out.println("Invalid Option. Try Again");
  79. System.out.println("");
  80. break;
  81. }
  82. } while (choice != 4);
  83. }
  84.  
  85. private static void register() {
  86. System.out.println("Create Username: ");
  87. System.out.println("Create Password: ");
  88. System.out.println("");
  89. }
  90.  
  91. private static void login() {
  92. System.out.println("Enter Username: ");
  93. System.out.println("Enter Password: ");
  94. System.out.println("");
  95.  
  96. for (int r = 1; r < 6; r++) {
  97. System.out.println("-------------Round " + r + "-------------");
  98. System.out.println("");
  99. System.out.println("Player 1: Enter any key to roll the dice");
  100. x = s.nextLine();
  101. int dice1 = Dice();
  102. System.out.println("Dice one: " + dice1);
  103. int dice2 = Dice();
  104. System.out.println("Dice two: " + dice2);
  105. int dice3 = 0;
  106. if (dice1 == dice2) {
  107. dice3 = Dice();
  108. System.out.println("Dice three: " + dice3);
  109. }
  110. int total = dice1 + dice2 + dice3;
  111. player1 = total + player1;
  112. if (player1 % 2 == 1) {
  113. player1 = player1 - 5;
  114. System.out.println("Player 1 TOTAL: " + player1);
  115. if (player1 < 0) {
  116. player1 = 0;
  117. System.out.println("Player 1 TOTAL: " + player1);
  118. }
  119. } else {
  120. player1 = player1 + 10;
  121. System.out.println("Player 1 TOTAL: " + player1);
  122. }
  123.  
  124. System.out.println("-------------------X-------------------");
  125.  
  126. System.out.println("Player 2: Enter any key to roll the dice");
  127. y = s.nextLine();
  128. dice1 = Dice();
  129. System.out.println("Dice one: " + dice1);
  130. dice2 = Dice();
  131. System.out.println("Dice two: " + dice2);
  132. dice3 = 0;
  133. if (dice1 == dice2) {
  134. dice3 = Dice();
  135. System.out.println("Dice three: " + dice3);
  136. }
  137. total = dice1 + dice2 + dice3;
  138. player2 = total + player2;
  139.  
  140. if (player2 % 2 == 1) {
  141. player2 = player2 - 5;
  142. System.out.println("Player 2 TOTAL: " + player2);
  143. if (player2 < 0) {
  144. player2 = 0;
  145. System.out.println("Player 2 TOTAL: " + player2);
  146. }
  147. } else {
  148. player2 = player2 + 10;
  149. System.out.println("Player 2 TOTAL: " + player2);
  150. }
  151.  
  152. }
  153. System.out.println("--------------------------------------");
  154. System.out.println("| Player 1 score = " + player1 + " |");
  155. System.out.println("--------------------------------------");
  156. System.out.println("| Player 2 score = " + player2 + " |");
  157. if (player1 > player2) {
  158. System.out.println("");
  159. System.out.println("THE WINNER IS: PLAYER 1");
  160. System.out.println("");
  161. } else {
  162. System.out.println("");
  163. System.out.println("THE WINNER IS: PLAYER 2");
  164. System.out.println("");
  165. }
  166. System.out.println("");
  167. if (player1 == player2) {
  168. sudden();
  169. }
  170. }
  171.  
  172. private static void hiscores() {
  173. System.out.println("Hi-Scores: ");
  174. System.out.println("");
  175. System.out.println("1. ");
  176. System.out.println("2. ");
  177. System.out.println("3. ");
  178. System.out.println("4. ");
  179. System.out.println("5. ");
  180. System.out.println("");
  181. }
  182.  
  183. private static void exit() {
  184. }
  185.  
  186. private static int Dice() {
  187. return (rand.nextInt(6) + 1);
  188. }
  189.  
  190. private static void sudden() {
  191. System.out.println("------------!Sudden Death!------------");
  192. while (player1 == player2) {
  193. System.out.println("Player 1: Enter any key to roll the dice");
  194. x = s.nextLine();
  195. int dice4 = Dice();
  196. System.out.println("Player 1 Score: " + dice4);
  197. System.out.println("--------------------------------------");
  198. System.out.println("Player 2: Enter any key to roll the dice");
  199. y = s.nextLine();
  200. dice4 = Dice();
  201. System.out.println("Player 2 Score: " + dice4);
  202. if (player1 >= player2) {
  203. System.out.println("The Winner is: Player 1");
  204. } else {
  205. System.out.println("The Winner is: Player 2");
  206. }
  207. }
  208. }
  209.  
  210. private static void fileReader() {
  211. try {
  212. BufferedReader br = new BufferedReader((new FileReader("N:/data.txt")));
  213. String a;
  214. while ((a = br.readLine()) != null) {
  215. String[] s = a.split(";");
  216. System.out.println(Arrays.toString(s));
  217. int hiscore = Integer.parseInt(s[2]);
  218. }
  219. System.out.println("Data Loaded Successfully");
  220. System.out.println("");
  221. br.close();
  222. } catch (IOException e) {
  223. System.out.println("Error: " + e.getMessage());
  224. }
  225.  
  226. }
  227.  
  228. private static void fileWriter() {
  229. try {
  230. FileWriter fw = new FileWriter("N:/newFile.txt");
  231. fw.write("This is some data.");
  232. fw.close();
  233. System.out.println("Data File Saved Successfully");
  234. System.out.println("");
  235. } catch (IOException e) {
  236. System.out.println("Error: " + e.getMessage());
  237. }
  238. }
  239.  
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement