Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sj166, agd19 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
36 changes: 36 additions & 0 deletions src/roulette/BetFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package roulette;

import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.List;

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

public class BetFactory {
List<String> betOptions = new ArrayList<String>(Arrays.asList({"RedBlack", "OddEven", "RedBlack"}));

public Bet createBet(int input){
Class betClass = Class.forName(betOptions.get(input));
Constructor betConstructor = betClass.getConstructor(String.class, Integer.class);
Bet bet = (Bet) betConstructor.newInstance(betOptions.get(input), input);
}

/*public Bet createBet(int input){
switch(input){
case 1:
return new RedBlack("Red or Black", 1);
case 2:
return new OddEven("Odd or Even", 1);
case 3:
return new ThreeConsecutive("Three in a Row", 11);

default:
return new RedBlack("default", 1);
}*/
//}

}


15 changes: 6 additions & 9 deletions src/roulette/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
public class Game {
// name of the game
private static final String DEFAULT_NAME = "Roulette";
private BetFactory myFactory = new BetFactory();
// 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;

/**
Expand Down Expand Up @@ -69,10 +66,10 @@ 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]));
for (int k = 0; k < 3; k++) {
System.out.println(String.format("%d) %s", (k + 1), myFactory.createBet(k)));
}
int response = ConsoleReader.promptRange("Please make a choice", 1, myPossibleBets.length);
return myPossibleBets[response - 1];
int response = ConsoleReader.promptRange("Please make a choice", 1, 3);
return myFactory.createBet(response);
}
}