Simon game
to continue. (After that any entries made into the worksheet will be automatically saved, and you can re-load the partially-completed worksheet in future - at which point you will be asked to auto-save it again).

Preliminaries

Total hints used: /

In the classic hand-held electronic game Simon, the device played a sequence of 'moves' and the players task was to remember and reproduce the sequence. Each of the four possible moves had a different colour (red, yellow, blue, green) associated with a different physical position and with a different audible tone. If the player reproduced the sequence correctly, the device played the sequence again with one more move added, and as the sequence lengthened, each move was shown for a shorter duration. If the player made a single incorrect move the game was over and the score reflected the longest length of sequence that the player reproduced correctly. The game was surprisingly engaging, and proved very popular.

We are going to build a simulation of the Simon game, with the four moves shown as large coloured circles in a row accompanied by audible tones. The player will use the four numeric keys 1 2 3 4 to input their memory of the sequence - the numbers corresponding to the four positions in the row.

We will make more than one use of a 'List' data structure in this program. A List is similar to an Array, but may be extended indefinitely (within in the limits of a computer's memory). A list may even start off empty and grow from there.

Iteration 1 - Draw a solid circle

Hint: The main so far
Total hints used: /

Iteration 2- Draw circle in four different locations and colours

Although the game will display only one circle at a time, we want to position it in one of four places in a row, with a different colour for each place. We already know that we will be using the 1 2 3 4 keys so, for the time being, we will simply define a name move which holds one of those four integer values.

Hint: The main so far
Total hints used: /

Iteration 3 - Move the display capability into a procedure

Whenever you find yourself with multiple instructions that together perform something that you could put a single name on, it is often good practice to move them into a named procedure. This keeps your code easier to read and to maintain. It is even more useful if you subsequently find yourself wanting to perform that same thing elsewhere in the code.

Total hints used: /

Iteration 4: Play a sequence

Total hints used: /

Iteration 5: Add sound

Hint 1: the new and modified instructions
Hint 2: complete procedure
Total hints used: /

Iteration 6: Build the random sequence

Total hints used: /

Iteration 7: Create the simonsTurn procedure

Now we're ready to complete the role of Simon (played by the computer) in the game, which is to repeatedly play a sequence of moves, adding a new random move each time. (We will later add the Player's role, interleaving between these plays). To keep the growing program easy to read, we will build the Simon's role into a new procedure.

Total hints used: /

Iteration 8: Start work on Player's turn

Total hints used: /

Iteration 9: Require the player to reproduce the whole sequence

We now need a loop that requires the player to reproduce each move in the sequence. We can determine the length of the sequence using sequence.length(), which might suggest using a for, or an each loop. The problem is that if the user makes a mistake (enters the wrong move, or a key that isn't a valid move) that's game over: we don't want to continue with the loop. So when the number of iterations through the loop is not fixed up-front we must use a 'conditional loop'. The condition for the loop continuing is that the user has hit the correct keys so far and that they haven't yet got to the end of the sequence.

Total hints used: /

Iteration 10: Polishing the game

Three bits of polishing are urgent - but write down anything else you can think of:

So ... Total hints used: /
You have completed the worksheet. Well done! If you have time try to make the following refinement, or think of some of your own:
This worksheet is copyright © Richard Pawson 2025, and protected by the Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International. If you copy and modify this worksheet you may not distribute your modified version (outside your own teaching institution) without the author's permission. Please email the author to report errors or suggest improvements.