
/**
 * Class that simulates betting on a roulette wheel.
 * 
 * @author Dave Reed 
 * @version 2/20/10
 */
public class RouletteGame1 {
    private RouletteWheel1 wheel;
    private int credits;

    /**
     * Constructor of objects of class RouletteGame.
     */
    public RouletteGame1() {
        this.wheel = new RouletteWheel1();
        this.credits = 0;
    }

    /**
     * Adds a number of credits to the player's account (assuming the number is positive).
     *   @param numCredits the number of credits to add
     */
    public void addCredits(int numCredits) {
        if (numCredits > 0) {
            this.credits += numCredits;
        }
    }
    
    /**
     * Determines the current number of credits in the player's account.
     *   @return the number of credits
     */
    public int checkCredits() {
        return this.credits;
    }
    
    /**
     * Makes a bet on a specific number and simulates the spin.  If the player wins,
     * they are credited with 35x their bet; otherwise they lose the bet amount.
     *   @param betAmount the number of credits being bet
     *   @param number the wheel number being bet upon (1-36)
     *   @return a message containing the spin and either "winner" or "loser", or
     *           "ILLEGAL BET" if the bet is illegal
     */
    public String makeBet(int betAmount, int number) {
        if (this.credits >= betAmount && number >= 1 && number <= 36) {
            int result = this.wheel.spin();
            
            if (result == number) {
                this.credits += 35*betAmount;
                return result + " - winner";
                
            }
            else {
                this.credits -= betAmount;
                return result + " - loser";
            }
        }
        else {
            return "ILLEGAL BET";
        }
    }

        /**
     * Makes an odd/even bet and simulates the spin.  If the player wins,
     * they are credited with the bet amount; otherwise they lose the bet amount.
     *   @param betAmount the number of credits being bet
     *   @param betType the type of bet ("odd" or "even")
     *   @return a message containing the spin and either "winner" or "loser", or
     *           "ILLEGAL BET" if the bet is illegal
     */
    public String makeBet(int betAmount, String betType) {
        if (this.credits >= betAmount && 
                     (betType.equals("odd") || betType.equals("even"))) {
            int result = this.wheel.spin();
            
            String resultType = "odd";
            if (result % 2 == 0) {
                resultType = "even";
            }
            
            if (result > 0 && betType.equals(resultType)) {
                this.credits += betAmount;
                return result + " - winner";
            }
            else {
                this.credits -= betAmount;
                return result + " - loser";
            }
        }
        else {
            return "ILLEGAL BET";
        }
    }

    /**
     * Repeatedly makes bets until the number of credits is doubled 
     * (or becomes 0).
     *   @param betAmount the number of credits being bet
     *   @param number the wheel number being bet upon (1-36)
     */
    public void playUntilDouble(int betAmount, int number) {
        int goalCredits = 2*this.credits;
        while (this.credits > 0 && this.credits < goalCredits) {
            System.out.println(this.makeBet(betAmount, number) +
                               " (" + this.credits + ")");
        }
    }
    
    /**
     * Repeatedly makes bets until the number of credits is doubled 
     * (or becomes 0).
     *   @param betAmount the number of credits being bet
     *   @param betType the type of bet ("odd" or "even")
     */
    public void playUntilDouble(int betAmount, String betType) {
        int goalCredits = 2*this.credits;
        while (this.credits > 0 && this.credits < goalCredits) {
            System.out.println(this.makeBet(betAmount, betType) +
                               " (" + this.credits + ")");
        }
    }
}
