diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/roulette/Bets.properties b/src/roulette/Bets.properties new file mode 100644 index 0000000..e88ae7d --- /dev/null +++ b/src/roulette/Bets.properties @@ -0,0 +1,3 @@ +OddEven = Odd or Even,1 +RedBlack = Red or Black,1 +ThreeConsecutive = Three in a Row,11 \ No newline at end of file diff --git a/src/roulette/Factory.java b/src/roulette/Factory.java new file mode 100644 index 0000000..d99cd51 --- /dev/null +++ b/src/roulette/Factory.java @@ -0,0 +1,64 @@ +package roulette; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; + +import roulette.bets.OddEven; +import roulette.bets.RedBlack; +import roulette.bets.ThreeConsecutive; +import util.ConsoleReader; + +public class Factory { + + List myBets; + private static ResourceBundle myResourceBundle = ResourceBundle.getBundle("roulette/Bets"); + + public Factory() { + // TODO Auto-generated constructor stub + myBets = new ArrayList(); + + } + + public static Bet createBet(String type) { + + Class c; + Bet bet; + try { + c = Class.forName("roulette."+ type ); + String[] args = myResourceBundle.getString(type).split(","); + bet = (Bet)c.getConstructor(String.class, Integer.class).newInstance(args[0], Integer.parseInt(args[1])); + return bet; + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch(IllegalAccessException e){ + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch(InvocationTargetException e){ + e.printStackTrace(); + } catch(NoSuchMethodException e){ + e.printStackTrace(); + } + + return null; + } + + + public List getBets(){ + return myBets; + } + + private Bet promptForBet () { + System.out.println("You can make one of the following types of bets:"); + for (int k = 0; k < myBets.size(); k++) { + System.out.println(myResourceBundle.getKeys()); + } + int response = ConsoleReader.promptRange("Please make a choice", 1, myBets.size()); + return myBets.get(response - 1); + } + +}