/* * CrapsLoopLoop.java * * Created on March 11, 2003, 9:32 AM */ package dice; import IO.Keyboard; /** * * @author mike */ public class CrapsLoopLoop { public static final double MINBET = 5.00; /** Creates a new instance of BabyCraps */ public CrapsLoopLoop() { } /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("This program is only for educational demonstration. No Gambling allowed! \n"); // create dice Die die1 = new Die(); Die die2 = new Die(); int gamesPlayed = 0; char answ = 'y'; System.out.println("How much do you have to lose? (I mean spend)"); double bankroll = Keyboard.readDouble(); // loop until they are out of money or don't want to continue while (((answ == 'y') || (answ == 'Y')) && (bankroll > 0)) { // simplifying assumption - bet is always same - the minimum double bet = MINBET; gamesPlayed++; // keep count for later display ///////////////////// // play one game - taken from CrapsLoop ///////////////////// boolean done = false; // default to not done int point = 0; // roll dice int val1 = die1.getRoll(); int val2 = die2.getRoll(); // get total int total = val1 + val2; System.out.println("Rolled: " + die1 + " " + die2 + " = " + total); // determine if win, lose, or keep rolling switch (total) { case 7: case 11: System.out.println("You win!!!"); // pays even money bankroll += bet; done = true; break; case 2: case 3: case 12: System.out.println("You lose :-("); bankroll -= bet; // pay casino done = true; break; default: point = total; System.out.println("We keep rolling"); } // roll until winner or loser while (!done) { // roll again val1 = die1.getRoll(); val2 = die2.getRoll(); // get total total = val1 + val2; System.out.println("Rolled: " + die1 + " " + die2 + " = " + total); // determine if win, lose or keep rolling if (total == 7) { System.out.println("You lose - 7 is bad here!"); bankroll -= bet; // pay casino done = true; } else if (total == point) { System.out.println("You win!!!!!!"); // pays even money bankroll += bet; done = true; } else { System.out.println("We keep rolling"); } } // end while System.out.println("After " + gamesPlayed + " games played," + " your bankroll is: " + bankroll); System.out.println("Do you want to continue playing?"); answ = Keyboard.readChar(); } // end outer while System.out.println("Ok, goodbye!"); } }