/* * LottoLogic.java * * Version: * $Id$ * * Revisions: * $Log$ */ import java.awt.*; import java.util.*; /** * Logic for the Lotto game. * * @author Paul Tymann * @author *** YOUR NAME GOES HERE *** * */ public class LottoLogic { // Constants /** * The number of rows in the lotto game */ private static final int NUM_ROWS = 7; /** * The number of colums in the lotto game. */ private static final int NUM_COLS = 7; /** * The total number of numbers than can be selected is given by * NUM_ROWS * NUM_COLS */ private static final int MAX_NUMBERS = NUM_ROWS * NUM_COLS; /** * The maximum number of numbers that may be selected by a user. */ private static final int MAX_SELECT = 6; /** * The reference to the GUI interacting with the user */ private LottoGUI gui; /** * Generator for the numbers */ private BallBox box = new BallBox( MAX_NUMBERS ); /** * Number of numbered buttons pressed by the user. This enables * the logic to ensure that the user selects exactly MAX_SELECT * numbers prior to making a draw. */ private int numButtonsPressed; /** * Construct a LottoLogic object connected to the specified * LottoGUI object. * * @param gui the GUI "connected" to the user. */ public LottoLogic( LottoGUI gui ) { this.gui = gui; } // The callbacks /** * "Play" the Lotto game once. Draws MAX_SELECT balls * from a BallBox and updates the GUI. */ public void draw() { System.out.println( "draw() was called" ); // *** INSERT YOUR CODE HERE *** } /** * Clears the board and resets the statistics back to zero. * Note that this method does not "unselect" the numbers * the player has selected. */ public void reset() { System.out.println( "reset() was called" ); // *** INSERT YOUR CODE HERE *** } /** * Updates the logic when a numbered button is pressed. * * @param button the number of the button pressed. */ public void buttonPressed( int button ) { gui.setSelected( button, true ); gui.setButtonColor( button, Color.blue ); // *** INSERT YOUR CODE HERE *** } /** * Prepare the logic for another draw. Resets the unselected * buttons back to their original state. The selected buttons * are changed back to the "selected" color. */ public void clearTheBoard() { numButtonsPressed = 0; // Reset the ball box for another draw box.refill(); // Step through each of the numbered buttons. Color the // unselected buttons light gray and the selected buttons // blue. for ( int i = 0; i < MAX_NUMBERS; i++ ) { if ( gui.isSelected( i ) ) { gui.setButtonColor( i, Color.blue ); numButtonsPressed++; } else { gui.setButtonColor( i, Color.lightGray ); } } } } // LottoLogic