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>
53 changes: 53 additions & 0 deletions src/roulette/Factory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package roulette;

import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

public class Factory {
private static final String PATH = "roulette.bets";
private Map<Integer, Parameters> betTypes;
private ResourceBundle myBundle;

public Factory () {
myBundle = ResourceBundle.getBundle(PATH);
betTypes = new HashMap<>();

int counter = 0;
for(String key: myBundle.keySet()) {
String className = "roulette." + key;
String DescriptionAndInt = myBundle.getString(key);
String [] arguments = DescriptionAndInt.split(",");
betTypes.put(counter, new Parameters(className, arguments[0], Integer.parseInt(arguments[1])));
counter++;
}

}

public Bet getBet (int index){
try {
Class<?> bet = Class.forName(betTypes.get(index).getGameName());
Constructor<?> c = bet.getConstructor(String.class, Integer.TYPE);
return (Bet) c.newInstance(betTypes.get(index).getDescription(), betTypes.get(index).getOdds());
} catch (ReflectiveOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;

}

public void print(){
for (int i = 0; i < betTypes.size(); i++) {
System.out.println(String.format("%d) %s", (i + 1), getBet(i).getDescription()));
}
}

public int getLenth(){
return betTypes.size();
}

}
15 changes: 5 additions & 10 deletions src/roulette/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,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 Factory betOptions;
private Wheel myWheel;

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

/**
Expand Down Expand Up @@ -66,10 +63,8 @@ public void play (Gambler player) {
*/
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].getDescription()));
}
int response = ConsoleReader.promptRange("Please make a choice", 1, myPossibleBets.length);
return myPossibleBets[response - 1];
betOptions.print();
int response = ConsoleReader.promptRange("Please make a choice", 1, betOptions.getLenth());
return betOptions.getBet(response - 1);
}
}
27 changes: 27 additions & 0 deletions src/roulette/Parameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package roulette;

public class Parameters {

private String description;
private String gameName;
private int odds;

public Parameters (String gameName, String description, int odds) {
this.description = description;
this.gameName = gameName;
this.odds = odds;
}

public String getDescription() {
return description;
}

public int getOdds() {
return odds;
}

public String getGameName() {
return gameName;
}

}
3 changes: 3 additions & 0 deletions src/roulette/bets.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RedBlack= Red or Black,1
ThreeConsecutive = Three in a row,11
OddEven= Odd or Even,1