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

    /**
     * Constructor of objects of class RouletteGame.
     */
    public RouletteGame() {
        this.wheel = new RouletteWheel();
        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) {
        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) {
        int result = this.wheel.spin();
        
        if (result == number) {
            this.credits += 35*betAmount;
            return result + " - winner";
            
        }
        else {
            this.credits -= betAmount;
            return result + " - loser";
        }
    }

        /**
     * 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
     *   @paramthe betType of bet ("odd" or "even")
     *   @return a message containing the spin and either "winner" or "loser"
     */
    public String makeBet(int betAmount, String betType) {
        int result = this.wheel.spin();
        
        String resultType = "odd";
        if (result % 2 == 0) {
            resultType = "even";
        }
        
        if (betType.equals(resultType)) {
            this.credits += betAmount;
            return result + " - winner";
        }
        else {
            this.credits -= betAmount;
            return result + " - loser";
        }
    }
}
