Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hilogame;
- import java.util.Scanner;
- import java.util.Random;
- public class HiLoGame {
- public static void Instructions() {
- System.out.println("RULES");
- System.out.println("Numbers 1 - 6 are low");
- System.out.println("Number 7 is neither high or low");
- System.out.println("Numbers 8 - 13 are high");
- System.out.println("You have 1000 points!");
- }
- public static void game() {
- Scanner input = new Scanner(System.in);
- Random rand = new Random();
- int random = rand.nextInt(20);
- int risked,pick;
- int points = 1000;
- while (points>0){
- System.out.print("How many points do you want to risk? ");
- risked = input.nextInt();
- System.out.print("Predict (9-high, 1-low): ");
- pick = input.nextInt();
- random = (int)Math.random()*13+1;
- if (random<7 && pick == 9 || random>7 && pick == 1){
- System.out.print("Congrats, you gained "+risked+" points!");
- points += risked;
- } else {
- System.out.print("Whoops, you lost "+risked+ " points :(");
- points -= risked;
- }
- System.out.print("You have "+points+" points!");
- }
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- Instructions();
- String ans;
- do {
- game();
- System.out.print("You lost... Do you want to play again? (y/n)");
- ans= input.next();
- } while(ans.equals("y"));
- input.close();
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement