Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Little console game just for fun - Bandit. You have $100.
- * You can make bids on your money. Lose if lost all money, win when get $1000.
- * Chance to win 50%. The fewer moves you spend, the better.
- */
- // ----- JAVA CODE -----
- package jsx;
- import java.util.Random;
- import java.util.Scanner;
- public class Bandit {
- static Scanner sc;
- static Random r;
- static int money, steps;
- public static void main(String[] args) {
- sc = new Scanner(System.in);
- r = new Random();
- money = 100;
- steps = 0;
- run();
- }
- static void run() {
- while (true) {
- System.out.println("Your money: " + money + " (" + steps + " steps)");
- System.out.print("Make your bid: ");
- int s = 0;
- try { s = Integer.valueOf(sc.nextLine()); } catch (NumberFormatException e) { }
- if (s < 1 || s > money) {
- System.out.println("Error! Incorrect value.");
- } else {
- steps++;
- System.out.println("Step " + steps + ": $" + s);
- if (r.nextInt(100) > 49) {
- money -= s;
- System.out.println("Fail! Fortune turned away from you.");
- } else {
- money += s;
- System.out.println("Luck! Goddess of luck winked at you.");
- }
- if (money < 1) {
- System.out.println("You lose! Bouncers have gone for you.");
- break;
- }
- if (money > 999) {
- System.out.println("You Win! This life is your.");
- break;
- }
- }
- System.out.println("-----------------\n");
- }
- }
- }
- // ----- BATCH CODE -----
- COLOR 0E
- java -jar Bandit.jar
- pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement