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
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
29 changes: 29 additions & 0 deletions src/roulette/BetFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package roulette;

import java.util.ArrayList;
import java.util.List;
import roulette.bets.*;
import util.ConsoleReader;

public class BetFactory {
List<Bet> bets = new ArrayList<Bet>();

public BetFactory() {
bets.add(new RedBlack("Red or Black", 1));
bets.add(new OddEven("Odd or Even", 1));
bets.add(new ThreeConsecutive("Three in a Row", 11));
}

/**
* Prompt the user to make a bet from a menu of choices.
*/
public Bet promptForBet () {
System.out.println("You can make one of the following types of bets:");
for (int k = 0; k < bets.size(); k++) {
System.out.println(String.format("%d) %s", (k + 1), bets.get(k)));
}
int response = ConsoleReader.promptRange("Please make a choice", 1, bets.size());
return bets.get(response - 1);
}

}
25 changes: 3 additions & 22 deletions src/roulette/Game.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package roulette;

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


Expand All @@ -14,19 +11,15 @@
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 Wheel myWheel;
private BetFactory betFactory;

/**
* Construct the game.
*/
public Game () {
myWheel = new Wheel();
betFactory = new BetFactory();
}

/**
Expand All @@ -47,7 +40,7 @@ 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();
Bet b = betFactory.promptForBet();
b.place();

System.out.print("Spinning ...");
Expand All @@ -63,16 +56,4 @@ public void play (Gambler player) {
}
player.updateBankroll(amount);
}

/**
* Prompt the user to make a bet from a menu of choices.
*/
private Bet 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];
}
}