Advertisement
JackHoughton00

HiLoGame

Apr 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package hilogame;
  2. import java.util.Scanner;
  3. import java.util.Random;
  4.  
  5.  
  6. public class HiLoGame {
  7. public static void Instructions() {
  8. System.out.println("RULES");
  9. System.out.println("Numbers 1 - 6 are low");
  10. System.out.println("Number 7 is neither high or low");
  11. System.out.println("Numbers 8 - 13 are high");
  12. System.out.println("You have 1000 points!");
  13. }
  14. public static void game() {
  15. Scanner input = new Scanner(System.in);
  16. Random rand = new Random();
  17. int random = rand.nextInt(20);
  18. int risked,pick;
  19. int points = 1000;
  20.  
  21.  
  22. while (points>0){
  23. System.out.print("How many points do you want to risk? ");
  24. risked = input.nextInt();
  25. System.out.print("Predict (9-high, 1-low): ");
  26. pick = input.nextInt();
  27. random = (int)Math.random()*13+1;
  28. if (random<7 && pick == 9 || random>7 && pick == 1){
  29. System.out.print("Congrats, you gained "+risked+" points!");
  30. points += risked;
  31.  
  32. } else {
  33. System.out.print("Whoops, you lost "+risked+ " points :(");
  34. points -= risked;
  35. }
  36. System.out.print("You have "+points+" points!");
  37. }
  38. }
  39.  
  40. public static void main(String[] args) {
  41. Scanner input = new Scanner(System.in);
  42. Instructions();
  43. String ans;
  44. do {
  45. game();
  46. System.out.print("You lost... Do you want to play again? (y/n)");
  47. ans= input.next();
  48. } while(ans.equals("y"));
  49. input.close();
  50. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement