/** * This class holds information the WinningBets. This class holds the * information stating what number, color, number range, row, third, and * whether odd or even are winning bets. * * @author Chris Juffre, cjuffre@cs.uml.edu * @since 1.0 * @version 1.0 */ public class WinningNumber { /** * Winning number * @since 1.0 * */ public int iNumber; /** * Code from RouletteConstants defining whether black or red * is the winner. It is possible to have no winner for this field if 0 or * 00 is the winning number. * @since 1.0 * */ public int iColor; /** * Code from RouletteConstants defining whether odd or even is * a winning bet. It is possible to have no winner for this field if 0 or * 00 is the winning number. * @since 1.0 * */ public int iOdd; /** * Code from RouletteConstants defining what range of numbers is * a winning bet. It is possible to have no winner for this field if 0 or * 00 is the winning number. * @since 1.0 * */ public int iRange; /** * Code from RouletteConstants defining what row of numbers is * a winning bet. It is possible to have no winner for this field if 0 or * 00 is the winning number. * @since 1.0 * */ public int iRow; /** * Code from RouletteConstants defining what third of numbers is * a winning bet. It is possible to have no winner for this field if 0 or * 00 is the winning number. * @since 1.0 * */ public int iThird; /** * This function calculates the winnings (or loses) from a given bet. * * @param bet The bet to compare with the WinningNumber to see if it is a winner. * @return The payout amount (negative if a lose). * @since 1.0 * */ public int calcWinnings(Bet bet) { /* Initializes Winnings to 0. */ int Winnings = 0; /* If the position of the bet is equal to any of the winning fields, calculate the amount won using the odds and set it equal to Winnings. If it doesn't match any of the fields, set the wager's value to be negative and return it. */ if(bet.Position == iNumber) Winnings = (bet.Wager * 36); else if(bet.Position == iColor) Winnings = (bet.Wager * 2); else if(bet.Position == iOdd) Winnings = (bet.Wager * 2); else if(bet.Position == iRange) Winnings = (bet.Wager * 2); else if(bet.Position == iRow) Winnings = (bet.Wager * 3); else if(bet.Position == iThird) Winnings = (bet.Wager * 3); else Winnings = (0 - bet.Wager); /* return the winnings */ return Winnings; } /** * Constructs a WinningNumber object based on the number selected during the spin. * * @param iSelectedNumber The number on the board selected by the spin * @since 1.0 * */ public WinningNumber(int iSelectedNumber) { /* Sets the actual winning number. */ iNumber = iSelectedNumber; /* If the number is 0 or 00 then nothing except an exact match can win. */ if(iSelectedNumber == 0 || iSelectedNumber == RouletteConstants.POS_NUM_00) iColor = iOdd = iRange = iRow = iThird = -1; /* If not 0 or 00, then calculate other winning bets. */ else { /* If winning number is odd, then set odd and red numbers as the winner. Otherwise black and even are the winners. */ if( (iSelectedNumber & 1) == 1) { iColor = RouletteConstants.POS_RED; iOdd = RouletteConstants.POS_ODD; } else { iColor = RouletteConstants.POS_BLACK; iOdd = RouletteConstants.POS_EVEN; } /* Set winning range based upon the winning number. */ if(iSelectedNumber > 0 && iSelectedNumber < 19) iRange = RouletteConstants.POS_1_TO_18; else iRange = RouletteConstants.POS_19_TO_36; /* Determine the range of the board that won given the winning number. */ if(iSelectedNumber > 0 && iSelectedNumber < 13) iThird = RouletteConstants.POS_FIRST_12; else if(iSelectedNumber > 12 && iSelectedNumber < 25) iThird = RouletteConstants.POS_SECOND_12; else iThird = RouletteConstants.POS_THIRD_12; /* Determine the winning row given the winning number. This is more trickier then calculating the range, cause each row is in increments of 3. To calculate this was can simply use a remainder to determine the row since we know what numbers are in each row. The top row goes 3, 6, 9... so if we divide the selected number be three and the remainder is 0, we know it is the top row. The same procedure can be applied to the other rows using a different remainder. */ if( (iSelectedNumber % 3) == 0) iRow = RouletteConstants.POS_TOP_ROW; else if( (iSelectedNumber % 3) == 1) iRow = RouletteConstants.POS_MIDDLE_ROW; else iRow = RouletteConstants.POS_BOTTOM_ROW; } } }