Lecture notes for the Introduction to multidisciplinary Computer Science II by James Tam | Return to the course web page |
Simon © Milton Bradley (part of Hasbro) was an electronic memory game that consisted of 4 large brightly colored buttons. The buttons would light up and beep in a random sequence and the player was challenged to duplicate the sequence. The first turn only lit up one bottom. The second turn would add another button to the sequence and so on. The game ends either when the player misses a button in a sequence or they've completed the game up to a certain level of difficulty.
Links showing how the original game looked/worked:
Using the Java classes: Button and Frame, a layout manager and the appropriate 'listener' classes you are to implement a single turn version of the Simon game. (Only the bonus version has to allow for multiple turns). The interface will consist of 4 button objects contained in a frame. By default the game will randomly "light up" a sequence of 4 buttons. The player can then try to duplicate the sequence. The game will compare the two sequences and indicate in the title bar whether the sequence was correct or not. The player should be able to pass to the program via a command line argument (an example program of how to get command line arguments) the number of buttons that will be lit up in a sequence. If no command line argument is given then the sequence length will be the default one.
Class
Responsibilities
Driver (or equivalent) Starting point of the program Simon (or equivalent) Stores information related to the game (e.g., how many buttons need to be randomly lit, how many have been lit already, if the sequence was correctly followed) and the operations needed to play the game (e.g., check if sequence was correct): A container that extends the Java Frame class Holds and operates the graphical controls needed to play the game (4 buttons) A button listener class that implements the ActionListener interface Processes button events A window listener class that extends the WindowAdaptor class Processes window events
The window for the Simon game should be rectangular with an appropriate title and a black background. The window contains 4 buttons with each one colored differently. Buttons are equal in size and each one takes up roughly a quarter of the containing window. The buttons sit in two rows with two buttons in a row. One or more of the Java layout manager classes will ensure that the buttons are proportioned and laid out the same way if the window is resized.
Figure 1: Layout of the controls in your game
To get credit for the bonus version" You get full marks for all the requirements (including non-functional requirements such as programming style) plus the player can play multiple rounds by pressing a “next round” button. The new round will be identical to the previous round (although a new random sequence of button presses will be generated) but the successive round will have one more button lit up. (That is if the first round had 4 buttons lit up in the sequence then the successive round would have 5 buttons and the round after that 6 buttons). The game should not proceed to the next round until the player presses the button to proceed. The game will continue playing turns until the player quits. At the end of each turn the game will display the results of the round (correct or incorrect sequence entered). (JT: the bonus could be quite challenging to complete because it will almost certainly require multi-threading so you should work on this one last).