Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class HiLo
- {
- private static int p1points = 1000;
- private static int p2points = 1000;
- private static int counter = 0;
- private static String name;
- private static String name2;
- public static void main (String [] args)
- {
- Scanner input = new Scanner (System.in);
- rules();
- }
- public static void rules()
- {
- Scanner input = new Scanner (System.in);
- System.out.println("High Low Game");
- System.out.println("");
- System.out.println("RULES");
- System.out.println("Number 1 through 6 are low");
- System.out.println("Number 8 through 13 are high");
- System.out.println("Number 7 is neither high nor low");
- System.out.println("");
- System.out.println("Enter player one name: ");
- String name = input.next();
- System.out.println(name + " has 1000 points");
- System.out.println("");
- System.out.println("Enter player two name: ");
- String name2 = input.next();
- System.out.println(name2 + " has 1000 points");
- isRisk();
- }
- public static void isRisk()
- {
- if(counter % 2 == 0)
- {
- Scanner input = new Scanner (System.in);
- System.out.println(name + " Enter points to risk: ");
- int risk = input.nextInt();
- System.out.println("");
- System.out.println("Predict (1=High, 0=Low): ");
- int guess = input.nextInt();
- if(guess == 1)
- {
- calcHigh(risk);
- }
- if(guess == 0)
- {
- calcLow(risk);
- }
- }
- else
- {
- Scanner input = new Scanner (System.in);
- System.out.println(name2 + " Enter points to risk: ");
- int risk = input.nextInt();
- System.out.println("");
- System.out.println("Predict (1=High, 0=Low): ");
- int guess = input.nextInt();
- if(guess == 1)
- {
- calcHigh(risk);
- }
- if(guess == 0)
- {
- calcLow(risk);
- }
- }
- }
- public static void calcHigh(int risk)
- {
- Scanner input = new Scanner (System.in);
- int ranum = (int)(13*Math.random()+1);
- int sentinel = 0;
- if(counter % 2 == 0)
- {
- do
- {
- if(ranum > 7)
- {
- risk = risk*2;
- p1points = p1points + risk;
- System.out.println("The number is " + ranum);
- System.out.println("Correct. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum < 7)
- {
- p1points = p1points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Incorrect. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum == 7)
- {
- p1points = p1points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Unlucky seven. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- counter++;
- isRisk();
- }while (sentinel !=1 || p1points > 4000 || p1points <= 0);
- }
- else
- {
- do
- {
- if(ranum > 7)
- {
- risk = risk*2;
- p2points = p2points + risk;
- System.out.println("The number is " + ranum);
- System.out.println("Correct. Your point total is: " + p2points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum < 7)
- {
- p2points = p2points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Incorrect. Your point total is: " + p2points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum == 7)
- {
- p2points = p2points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Unlucky seven. Your point total is: " + p2points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- counter++;
- isRisk();
- }while (sentinel !=1 || p2points > 4000 || p2points <= 0);
- }
- }
- public static void calcLow(int risk)
- {
- Scanner input = new Scanner (System.in);
- int ranum = (int)(13*Math.random()+1);
- int sentinel =0;
- if(counter % 2 == 0)
- {
- do
- {
- if(ranum > 7)
- {
- p1points = p1points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Incorrect. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum < 7)
- {
- risk = risk*2;
- p1points = p1points + risk;
- System.out.println("The number is " + ranum);
- System.out.println("Correct. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum == 7)
- {
- p1points = p1points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Unlucky seven. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- counter++;
- isRisk();
- }while (sentinel !=1 || p1points > 4000 || p1points <= 0);
- }
- else
- {
- do
- {
- if(ranum > 7)
- {
- p2points = p2points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Incorrect. Your point total is: " + p1points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum < 7)
- {
- risk = risk*2;
- p2points = p2points + risk;
- System.out.println("The number is " + ranum);
- System.out.println("Correct. Your point total is: " + p2points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- if(ranum == 7)
- {
- p2points = p2points - risk;
- System.out.println("The number is " + ranum);
- System.out.println("Unlucky seven. Your point total is: " + p2points);
- System.out.print("Play again? (Press 0 for yes 1 for no): ");
- int response = input.nextInt();
- if(response == 1)
- {
- sentinel = 1;
- }
- }
- counter++;
- isRisk();
- }while (sentinel !=1 || p2points > 4000 || p2points <= 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement