import java.applet.Applet; import java.awt.Graphics; import java.awt.Point; import java.awt.Font; import java.awt.Color; /** * This class contains all the information on a particular bet. This * class holds information about what spot on the roulette table the * bet was placed on, and what amount of wager was placed on that * position. * * @author Chris Juffre * @since 1.0 * @version 1.0 */ public class Bet { /** * The position on the table the bet was made. For a list of * positions see RouletteConstants. * * @since 1.0 */ public int Position; /** * The dollar amount wagered on the position. * * @since 1.0 */ public int Wager; /** * Bet Constructor - Creates a Bet object given the position on the board and the wager. * * @param Position Position index on the board where the bet was placed. * @param Wager The amount of money in dollars wagered on the roulette index position. * * @since 1.0 */ public Bet(int Position, int Wager) { this.Position = Position; this.Wager = Wager; } /** * This function prints the bet in string form to be placed in the * current bets TextArea display. * * @return String to be added to the current bets text area * @since 1.0 */ public String printWager() { String strBet = new String(); /* Make not that it is a wager. */ strBet = "Wager $" + Integer.toString(Wager) + " on "; /* Get string representation of position. */ if(Position >= 0 && Position <= 36) strBet += Integer.toString(Position); else if(Position == 37) strBet += "00"; else if(Position == 38) strBet += "the Bottom 2:1 Row"; else if(Position == 39) strBet += "the Middle 2:1 Row"; else if(Position == 40) strBet += "the Top 2:1 Row"; else if(Position == 41) strBet += "the First 12 Numbers"; else if(Position == 42) strBet += "the Second 12 Numbers"; else if(Position == 43) strBet += "the Third 12 Numbers"; else if(Position == 44) strBet += "Numbers 1 through 18"; else if(Position == 45) strBet += "EVEN Numbers"; else if(Position == 46) strBet += "RED Numbers"; else if(Position == 47) strBet += "BLACK Numbers"; else if(Position == 48) strBet += "ODD Numbers"; else if(Position == 49) strBet += "Numbers 19 through 36"; /* Add a carriage return. */ strBet += "\n"; return strBet; // return the string formulated } /** * This function prints bets in the form they need to be displayed * when printing the report of wins and loses. * * @return String to be added to the report of winning or losing bets * @since 1.0 */ public String printResult() { String strBet = new String(); /* Just a dollar sign representation since it is not longer a wager. */ strBet = "$" + Integer.toString(Wager) + " on "; /* Create string representation of the position. */ if(Position >= 0 && Position <= 36) strBet += Integer.toString(Position); else if(Position == 37) strBet += "00"; else if(Position == 38) strBet += "the Bottom 2:1 Row"; else if(Position == 39) strBet += "the Middle 2:1 Row"; else if(Position == 40) strBet += "the Top 2:1 Row"; else if(Position == 41) strBet += "the First 12 Numbers"; else if(Position == 42) strBet += "the Second 12 Numbers"; else if(Position == 43) strBet += "the Third 12 Numbers"; else if(Position == 44) strBet += "Numbers 1 through 18"; else if(Position == 45) strBet += "EVEN Numbers"; else if(Position == 46) strBet += "RED Numbers"; else if(Position == 47) strBet += "BLACK Numbers"; else if(Position == 48) strBet += "ODD Numbers"; else if(Position == 49) strBet += "Numbers 19 through 36"; return strBet; // return the formulated string with no carriage return appended } /** * This function paints a "betting chip" on the board in the position * where that bet is placed with the wager written in the middle of the * chip. * * @param g Graphics context of the applet. * @param app The main applet context. * @since 1.0 */ public void paintChipOnBoard(Graphics g, Roulette app) { /* Set font for the chip and get the center point of the betting rectangle on the board. */ Font fChipWager = new Font("SansSerif", Font.PLAIN, 10); g.setFont(fChipWager); /* Get the center point of the betting square. */ Point p = getPointOfPosition(app); /* Log the position for debugging purposes */ System.out.println("Position " + Integer.toString(Position) + " location is at X:" + Integer.toString((int) p.getX()) + " Y:" + Integer.toString((int) p.getY())); /* Set the radius of the inner and outer parts of the chip. */ int iInnerChip = (app.iNumberWidth - 25); int iOuterChip = (app.iNumberWidth - 15); /* If it is number. */ if(Position >= 0 && Position <= 37) { /* Outer area of chip. */ g.setColor(Color.magenta); g.fillArc( (int) p.getX() - (iOuterChip / 2), (int) p.getY() - (iOuterChip / 2), iOuterChip, iOuterChip, 0, 360); /* Inner circle of chip. */ g.setColor(Color.yellow); g.fillArc( (int) p.getX() - (iInnerChip / 2), (int) p.getY() - (iInnerChip / 2), iInnerChip, iInnerChip, 0, 360); /* String of chip. */ g.setColor(Color.black); g.drawString(Integer.toString(Wager), ((int) p.getX()) - (app.iNumberWidth / 2) + app.getBlockPositionX(Integer.toString(Wager), g, app.iNumberWidth), ((int) p.getY()) - (app.iNumberWidth / 2) + app.getBlockPositionY(Integer.toString(Wager), g, app.iNumberWidth) ); } /* All other chips are drawn with and inner, outer, and string in the middle as above, so I will not document the inside of every if clause. The only difference if that the size of the ship changes on different betting areas. */ /* If a row bet. */ else if(Position >= 38 && Position <= 40) { g.setColor(Color.magenta); g.fillArc( (int) p.getX() - (iOuterChip / 2), (int) p.getY() - (iOuterChip / 2), iOuterChip, iOuterChip, 0, 360); g.setColor(Color.yellow); g.fillArc( (int) p.getX() - (iInnerChip / 2), (int) p.getY() - (iInnerChip / 2), iInnerChip, iInnerChip, 0, 360); g.setColor(Color.black); g.drawString(Integer.toString(Wager), ((int) p.getX()) - 37 + app.getBlockPositionX(Integer.toString(Wager), g, 75), ((int) p.getY()) - (app.iNumberWidth / 2) + app.getBlockPositionY(Integer.toString(Wager), g, app.iNumberWidth) ); } /* If a third bet. */ else if(Position >= 41 && Position <= 43) { g.setColor(Color.magenta); g.fillArc( (int) p.getX() - (iOuterChip / 2), (int) p.getY() - (iOuterChip / 2), iOuterChip, iOuterChip, 0, 360); g.setColor(Color.yellow); g.fillArc( (int) p.getX() - (iInnerChip / 2), (int) p.getY() - (iInnerChip / 2), iInnerChip, iInnerChip, 0, 360); g.setColor(Color.black); g.drawString(Integer.toString(Wager), ((int) p.getX()) - 100 + app.getBlockPositionX(Integer.toString(Wager), g, 200), ((int) p.getY()) - 50 + app.getBlockPositionY(Integer.toString(Wager), g, 100) ); } /* If a bet in the last row on roulette board (colors, range, ect...) */ else if(Position >= 44 && Position <= 49) { g.setColor(Color.magenta); g.fillArc( (int) p.getX() - (iOuterChip / 2), (int) p.getY() - (iOuterChip / 2), iOuterChip, iOuterChip, 0, 360); g.setColor(Color.yellow); g.fillArc( (int) p.getX() - (iInnerChip / 2), (int) p.getY() - (iInnerChip / 2), iInnerChip, iInnerChip, 0, 360); g.setColor(Color.black); g.drawString(Integer.toString(Wager), ((int) p.getX()) - 50 + app.getBlockPositionX(Integer.toString(Wager), g, 100), ((int) p.getY()) - 25 + app.getBlockPositionY(Integer.toString(Wager), g, 50) ); } } /** * This function returns the point representing the center of a betting rectangle. * * @param app The Roulette applet to being drawn on containing margin data * @return The center point of the betting square * @since 1.0 */ private Point getPointOfPosition(Roulette app) { /* Two clause below return the point of 0 and 00 */ if(Position == RouletteConstants.POS_NUM_00) return new Point(app.iSideBorders + (app.iNumberWidth / 2), app.iTopBorder + 50); else if(Position == RouletteConstants.POS_NUM_0) return new Point(app.iSideBorders + (app.iNumberWidth / 2), app.iTopBorder + 100); /* Returns the point of any given number */ else if(Position > 0 && Position < 37) { /* Initializes the row depending on the position clicked. */ int row; if(Position == 1) row = 2; else if(Position == 2) row = 1; else row = 0; /* Initializes the column. */ int column = 1; /* The temporary roulette number position used to calculate the column. */ int tempNumber = Position; /* Increases the column by one every time the loop goes. For example if it is 6, then the loop will go once since 6 - 3 is 3. The column will be two. Also calculates the row the number is in. */ while(tempNumber != 1 && tempNumber != 2 && tempNumber != 3) { tempNumber -= 3; // Decrease the temp index /* If at the final case set the current row using zero based numbers. */ if(tempNumber == 3) row = 0; else if(tempNumber == 2) row = 1; else row = 2; column++; // Increase column by one } /* Create a point using the row and column data. Simple calculations. */ return new Point(app.iSideBorders + (app.iNumberWidth * column) + (app.iNumberWidth / 2), app.iTopBorder + (app.iNumberWidth * row) + (app.iNumberWidth / 2)); } /* The three 2:1 spots. */ else if(Position > 37 && Position < 41) { if(Position == 40) return new Point(app.iSideBorders + (app.iNumberWidth * 13) + 37, app.iTopBorder + (app.iNumberWidth / 2)); else if(Position == 39) return new Point(app.iSideBorders + (app.iNumberWidth * 13) + 37, app.iTopBorder + app.iNumberWidth + (app.iNumberWidth / 2)); else return new Point(app.iSideBorders + (app.iNumberWidth * 13) + 37, app.iTopBorder + (app.iNumberWidth * 2) + (app.iNumberWidth / 2)); } /* The three thirds spots. */ else if(Position > 40 && Position < 44) return new Point(app.iSideBorders + app.iNumberWidth + (200 * (Position - 41)) + 100, app.iTopBorder + (app.iNumberWidth * 3) + 50); /* The very bottom row of the roulette table. */ else if(Position > 43 && Position < 50) return new Point(app.iSideBorders + app.iNumberWidth + (100 * (Position - 44)) + 50, app.iTopBorder + (app.iNumberWidth * 3) + 125); return null; // Only returns in case of error } }