Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/roulette/BetFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package roulette;

import roulette.bets.OddEven;
import roulette.bets.RedBlack;
import roulette.bets.ThreeConsecutive;
import util.ConsoleReader;

public class BetFactory {

public BetFactory() {}

public static Bet placeBet(int betNum){
String result = "";
Bet b = null;
switch (betNum) {
case 1: result = ConsoleReader.promptOneOf("Please bet", Wheel.BLACK, Wheel.RED);
b = new RedBlack("Red or Black", 1);
break;
case 2: result = ConsoleReader.promptOneOf("Please bet", "even", "odd");
b = new OddEven("Odd or Even", 1);
break;
case 3: result = "" + ConsoleReader.promptRange("Enter first of three consecutive numbers",
1, Wheel.NUM_SPOTS - 3);
b = new ThreeConsecutive("Three in a Row", 11);
break;
}

System.out.println();
return b;
}

}
16 changes: 9 additions & 7 deletions src/roulette/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public class Game {
// name of the game
private static final String DEFAULT_NAME = "Roulette";
// add new bet subclasses here
private Bet[] myPossibleBets = {
new RedBlack("Red or Black", 1),
new OddEven("Odd or Even", 1),
new ThreeConsecutive("Three in a Row", 11),
private String[] myPossibleBets = {
"Red or Black",
"Odd or Even",
"Three in a Row"
};
private Wheel myWheel;
private BetFactory betFactory;

/**
* Construct the game.
Expand All @@ -47,7 +48,8 @@ public String getName () {
public void play (Gambler player) {
int amount = ConsoleReader.promptRange("How much do you want to bet",
0, player.getBankroll());
Bet b = promptForBet();
int betNum = promptForBet();
Bet b = BetFactory.placeBet(betNum);
b.place();

System.out.print("Spinning ...");
Expand All @@ -67,12 +69,12 @@ public void play (Gambler player) {
/**
* Prompt the user to make a bet from a menu of choices.
*/
private Bet promptForBet () {
private int promptForBet () {
System.out.println("You can make one of the following types of bets:");
for (int k = 0; k < myPossibleBets.length; k++) {
System.out.println(String.format("%d) %s", (k + 1), myPossibleBets[k]));
}
int response = ConsoleReader.promptRange("Please make a choice", 1, myPossibleBets.length);
return myPossibleBets[response - 1];
return response;
}
}