Question
Java, GUI and Layout Manager You will create a modified version of the Milton Bradley electronic game named SIMON. First review how the game is
Java, GUI and Layout Manager
You will create a modified version of the Milton Bradley electronic game named SIMON. First review how the game is actually played DO NOT WORRY WE ARE NOT CODING THE ENTIRE GAME.
How the real game is played: 1. SIMON will play one signal (light a color lens on the game while playing the musical note associated with that color). 2. SIMON will wait while you duplicate that sequence by pressing on the color lens that SIMON just played. 3. SIMON will duplicate the first signal and will add one additional signal (light with musical note) now playing two signals (lighting each and playing a musical note with each). 4. SIMON will wait while your repeat the sequence. 5. SIMON will duplicate these first two signals and add one. 6. SIMON waits for you to play the same signals. 7. Continue in this manner as long as you can repeat each sequence of signals correctly. 8. As you progress, the signals will play at a quicker pace. 9. If you fail to repeat a sequence exactly or if you take more than 5 seconds to repeat a signal, SIMON responds with a "RAZZ" sound; you have lost, and this sequence of signals is over.
You will not program the entire SIMON game. You will only code a portion of the game.
1- Use a Layout Manager for this assignment - one of the layouts presented in Chapter 6. 2- Create four GUI components that simulate the four buttons on the Simon hand-held game. Lets call these simulated buttons color controls so that you dont confuse them with buttons in a GUI. You could use JLabel controls to simulate the Simon buttons. For example below is one possible configuration for the color controls
3- Start with the background color of all 4 JLabels set to gray (or white) indicating the color controls are not lighted. 4- Create a start and stop buttons in the GUI and a Timer object to synchronize the lighting of the JLabels. 5-
Inside the listener for the start button: For our version of the game, you will simply light up one JLabel at a time in a random sequence of 8. To do this, populate an integer array to hold 8 colors which are represent as integers: 1 represents red 2 represents green 3 represents yellow 4 represents blue Generate 8 random numbers in the range 1-4 and load the values into the array.
Lets look at an example: Suppose you generated the 8 random number below and stored them in the array: 2 3 2 1 4 4 2 1 This array would mean you need to light up the JLabels in the following order: Green (2) Yellow (3) Green (2) Red (1) Blue (4) Blue (4) Green (2) Red (1) After the numbers are loaded into the array, you will need to keep track of where you are as you light each color. Create an integer variable, lets call it pointer. It will track where you are in the array begin by initializing pointer to zero (the first index in the array). Start the timer object so that the sequence of lighting colors can begin.
Inside the listener for the timer: The Timer is the key! You do NOT need to create a loop to go through the array. The time will control that. When timer begins Turn all 4 JLabel controls to gray/white. This simulates turning off the lights. Using pointer as the index to your array, use the next value in the array to light up the correct JLabel. For example, if the next value in the array is 2 you need to light up the Green control. In that case, you would change the background color of the second JLabel from gray/white to green. Increment the pointer so that you will use the next element in the array the next time the timer goes off again. Make sure you stop after the eighth color is displayed. At this point, if it working correctly, you will see the colors appear one at a time on the controls (changing from gray/white to a specific color).
Inside the listener for the stop button: When the Stop button is clicked, the timer should stop. You can also set the pointer back to zero.
Red Control 1Control 2 Green Yellow Control 3 Control 4 Blue Red Control 1Control 2 Green Yellow Control 3 Control 4 BlueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started