Advertisement
MagisterRain

Bandit

Jul 20th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. /*
  2. * Little console game just for fun - Bandit. You have $100.
  3. * You can make bids on your money. Lose if lost all money, win when get $1000.
  4. * Chance to win 50%. The fewer moves you spend, the better.
  5. */
  6.  
  7. // ----- JAVA CODE -----
  8. package jsx;
  9.  
  10. import java.util.Random;
  11. import java.util.Scanner;
  12.  
  13. public class Bandit {
  14.  
  15.     static Scanner sc;
  16.     static Random r;
  17.  
  18.     static int money, steps;
  19.  
  20.     public static void main(String[] args) {
  21.         sc = new Scanner(System.in);
  22.         r = new Random();
  23.         money = 100;
  24.         steps = 0;
  25.         run();
  26.     }
  27.  
  28.     static void run() {
  29.         while (true) {
  30.             System.out.println("Your money: " + money + " (" + steps + " steps)");
  31.             System.out.print("Make your bid: ");
  32.             int s = 0;
  33.             try { s = Integer.valueOf(sc.nextLine()); } catch (NumberFormatException e) { }
  34.             if (s < 1 || s > money) {
  35.                 System.out.println("Error! Incorrect value.");
  36.             } else {
  37.                 steps++;
  38.                 System.out.println("Step " + steps + ": $" + s);
  39.                 if (r.nextInt(100) > 49) {
  40.                     money -= s;
  41.                     System.out.println("Fail! Fortune turned away from you.");
  42.                 } else {
  43.                     money += s;
  44.                     System.out.println("Luck! Goddess of luck winked at you.");
  45.                 }
  46.                 if (money < 1) {
  47.                     System.out.println("You lose! Bouncers have gone for you.");
  48.                     break;
  49.                 }
  50.                 if (money > 999) {
  51.                     System.out.println("You Win! This life is your.");
  52.                     break;
  53.                 }
  54.             }
  55.             System.out.println("-----------------\n");
  56.         }
  57.     }
  58.  
  59. }
  60.  
  61. // ----- BATCH CODE -----
  62. COLOR 0E
  63. java -jar Bandit.jar
  64. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement