Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class HiLo
  3. {
  4. private static int p1points = 1000;
  5. private static int p2points = 1000;
  6. private static int counter = 0;
  7. private static String name;
  8. private static String name2;
  9. public static void main (String [] args)
  10. {
  11. Scanner input = new Scanner (System.in);
  12. rules();
  13.  
  14. }
  15.  
  16. public static void rules()
  17. {
  18. Scanner input = new Scanner (System.in);
  19. System.out.println("High Low Game");
  20. System.out.println("");
  21. System.out.println("RULES");
  22. System.out.println("Number 1 through 6 are low");
  23. System.out.println("Number 8 through 13 are high");
  24. System.out.println("Number 7 is neither high nor low");
  25. System.out.println("");
  26.  
  27. System.out.println("Enter player one name: ");
  28. String name = input.next();
  29. System.out.println(name + " has 1000 points");
  30. System.out.println("");
  31. System.out.println("Enter player two name: ");
  32. String name2 = input.next();
  33. System.out.println(name2 + " has 1000 points");
  34. isRisk();
  35. }
  36.  
  37. public static void isRisk()
  38. {
  39.  
  40. if(counter % 2 == 0)
  41. {
  42. Scanner input = new Scanner (System.in);
  43. System.out.println(name + " Enter points to risk: ");
  44. int risk = input.nextInt();
  45. System.out.println("");
  46. System.out.println("Predict (1=High, 0=Low): ");
  47. int guess = input.nextInt();
  48. if(guess == 1)
  49. {
  50. calcHigh(risk);
  51. }
  52. if(guess == 0)
  53. {
  54. calcLow(risk);
  55. }
  56. }
  57. else
  58. {
  59. Scanner input = new Scanner (System.in);
  60. System.out.println(name2 + " Enter points to risk: ");
  61. int risk = input.nextInt();
  62. System.out.println("");
  63. System.out.println("Predict (1=High, 0=Low): ");
  64. int guess = input.nextInt();
  65. if(guess == 1)
  66. {
  67. calcHigh(risk);
  68. }
  69. if(guess == 0)
  70. {
  71. calcLow(risk);
  72. }
  73. }
  74. }
  75.  
  76. public static void calcHigh(int risk)
  77. {
  78. Scanner input = new Scanner (System.in);
  79. int ranum = (int)(13*Math.random()+1);
  80. int sentinel = 0;
  81. if(counter % 2 == 0)
  82. {
  83. do
  84. {
  85. if(ranum > 7)
  86. {
  87. risk = risk*2;
  88. p1points = p1points + risk;
  89. System.out.println("The number is " + ranum);
  90. System.out.println("Correct. Your point total is: " + p1points);
  91. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  92. int response = input.nextInt();
  93. if(response == 1)
  94. {
  95. sentinel = 1;
  96. }
  97.  
  98. }
  99. if(ranum < 7)
  100. {
  101. p1points = p1points - risk;
  102. System.out.println("The number is " + ranum);
  103. System.out.println("Incorrect. Your point total is: " + p1points);
  104. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  105. int response = input.nextInt();
  106. if(response == 1)
  107. {
  108. sentinel = 1;
  109. }
  110. }
  111. if(ranum == 7)
  112. {
  113. p1points = p1points - risk;
  114. System.out.println("The number is " + ranum);
  115. System.out.println("Unlucky seven. Your point total is: " + p1points);
  116. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  117. int response = input.nextInt();
  118. if(response == 1)
  119. {
  120. sentinel = 1;
  121. }
  122. }
  123. counter++;
  124. isRisk();
  125. }while (sentinel !=1 || p1points > 4000 || p1points <= 0);
  126. }
  127. else
  128. {
  129. do
  130. {
  131. if(ranum > 7)
  132. {
  133. risk = risk*2;
  134. p2points = p2points + risk;
  135. System.out.println("The number is " + ranum);
  136. System.out.println("Correct. Your point total is: " + p2points);
  137. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  138. int response = input.nextInt();
  139. if(response == 1)
  140. {
  141. sentinel = 1;
  142. }
  143.  
  144. }
  145. if(ranum < 7)
  146. {
  147. p2points = p2points - risk;
  148. System.out.println("The number is " + ranum);
  149. System.out.println("Incorrect. Your point total is: " + p2points);
  150. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  151. int response = input.nextInt();
  152. if(response == 1)
  153. {
  154. sentinel = 1;
  155. }
  156. }
  157. if(ranum == 7)
  158. {
  159. p2points = p2points - risk;
  160. System.out.println("The number is " + ranum);
  161. System.out.println("Unlucky seven. Your point total is: " + p2points);
  162. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  163. int response = input.nextInt();
  164. if(response == 1)
  165. {
  166. sentinel = 1;
  167. }
  168. }
  169. counter++;
  170. isRisk();
  171. }while (sentinel !=1 || p2points > 4000 || p2points <= 0);
  172. }
  173. }
  174.  
  175. public static void calcLow(int risk)
  176. {
  177. Scanner input = new Scanner (System.in);
  178. int ranum = (int)(13*Math.random()+1);
  179. int sentinel =0;
  180. if(counter % 2 == 0)
  181. {
  182. do
  183. {
  184. if(ranum > 7)
  185. {
  186. p1points = p1points - risk;
  187. System.out.println("The number is " + ranum);
  188. System.out.println("Incorrect. Your point total is: " + p1points);
  189. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  190. int response = input.nextInt();
  191. if(response == 1)
  192. {
  193. sentinel = 1;
  194. }
  195. }
  196. if(ranum < 7)
  197. {
  198. risk = risk*2;
  199. p1points = p1points + risk;
  200. System.out.println("The number is " + ranum);
  201. System.out.println("Correct. Your point total is: " + p1points);
  202. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  203. int response = input.nextInt();
  204. if(response == 1)
  205. {
  206. sentinel = 1;
  207. }
  208. }
  209. if(ranum == 7)
  210. {
  211. p1points = p1points - risk;
  212. System.out.println("The number is " + ranum);
  213. System.out.println("Unlucky seven. Your point total is: " + p1points);
  214. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  215. int response = input.nextInt();
  216. if(response == 1)
  217. {
  218. sentinel = 1;
  219. }
  220. }
  221. counter++;
  222. isRisk();
  223. }while (sentinel !=1 || p1points > 4000 || p1points <= 0);
  224. }
  225.  
  226. else
  227. {
  228. do
  229. {
  230. if(ranum > 7)
  231. {
  232. p2points = p2points - risk;
  233. System.out.println("The number is " + ranum);
  234. System.out.println("Incorrect. Your point total is: " + p1points);
  235. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  236. int response = input.nextInt();
  237. if(response == 1)
  238. {
  239. sentinel = 1;
  240. }
  241. }
  242. if(ranum < 7)
  243. {
  244. risk = risk*2;
  245. p2points = p2points + risk;
  246. System.out.println("The number is " + ranum);
  247. System.out.println("Correct. Your point total is: " + p2points);
  248. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  249. int response = input.nextInt();
  250. if(response == 1)
  251. {
  252. sentinel = 1;
  253. }
  254. }
  255. if(ranum == 7)
  256. {
  257. p2points = p2points - risk;
  258. System.out.println("The number is " + ranum);
  259. System.out.println("Unlucky seven. Your point total is: " + p2points);
  260. System.out.print("Play again? (Press 0 for yes 1 for no): ");
  261. int response = input.nextInt();
  262. if(response == 1)
  263. {
  264. sentinel = 1;
  265. }
  266. }
  267. counter++;
  268. isRisk();
  269. }while (sentinel !=1 || p2points > 4000 || p2points <= 0);
  270. }
  271. }
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement