The game of Simon has been popular for many years. The basic premise is this:
Device does an action (display a light, plays a sound etc.) Player has to repeat the action (press a button corresponding to the light/sound etc). The device then does the original action plus a new action. Player has to repeat the sequence. Each time the player gets the sequence right, the device adds another action onto the sequence making it harder and harder to remember.
This is my EV3 version of the Simon Game.
Hardware:
I’m using 3 colour sensors to represent the actions that the device can show. If you set the Colour sensor to measure ambient intensity, the LED inside glows blue. If you set it to measure reflected intensity, then it glows red. I’ll be using these as flashing lights only, and am not interested in the actual sensor readings that they generate.
I’m using the Brick buttons (left, centre, right) as the player inputs. If the left Colour Sensor goes red, that means the Player has to press the left Brick Button to match the sequence.
Software:
Initialisation
Create a Numeric Variable Array and set it to 0
Set each Colour Sensor to be in Ambient mode (showing a blue light)
Generate sequence
Create a Random number, between 1 and 3, and append it to array (append is a fancy way of saying tack on a new number to the end of the array).
I then show on the EV3 screen the length of the array to let the Player know what level they’re up to. If the array/sequence is 5 actions long, then they are on Level 5.
Take the random number, if it is 1, play a low note and briefly change Colour Sensor 1 to red and then back to blue. If the random number is 2 or 3, play a medium / high note and flash the appropriate Colour Sensor.
Repeat this process as many times as there are numbers in the array. ie. If the array/sequence is 6 numbers long, then repeat this 6 times.
Check the sequence
Wait for either the Left, Centre or Right Brick button to be pressed. Each button represents a number, and this number is checked with the equivalent position in the array. If the numbers are equal, it means the Player pressed the right button for that part of the sequence. A brief high pitched note is played to indicate success and the next number in the sequence is checked. If the numbers don’t matched, then it means they got it out of sequence. A suitable sound is played and the main loop is interrupted (exited). The score stays on screen for 5 seconds so you can see what level you got to.