In this project, we'll finish the development of our Simon Says pattern-matching game by adding a final sequence when the player loses.
The hardware setup for this project should be the same setup that was
completed for the project. Here's a reminder:
The last piece of our game is to add in a final sequence for when the user
makes a mistake and we drop through the while
loop.
When this happens, we want to do the following:
If the user has lost due to a time-out (he didn't hit a button in time), we light up all the LEDs
If the user has lost due to hitting a wrong button in the sequence, we light up the LED that was incorrectly pressed
We then play an error tone
Finally, we play the correct sequence one last time (quickly)
Here is what that code will look like:
Here is what the final code for this project looks like (with new changes highlighted with arrows) — go have some fun playing and don't forget to try the challenges!
You now have a basic Simon Says game you can play, but there are many variations you can try. How complex you go with any variation is up to your own imagination:
Reverse: Have the user repeat the sequence of button presses in reverse.
Inverted Lights: For each button in the play sequence, light up all 3 of the LEDs NOT next to the button. The gameplay is the same, but it is much more confusing to remember which button to press.
Mixed Inverted Lights: Sometimes invert the LEDs (as suggested above), and sometimes don't — but do this randomly.
Two at a Time: Do a random sequence that displays two LEDs on at the same time.
Onesie Twosie: Sometimes display two LEDs at the same time (as suggested above), and sometimes don't — but do this randomly.
Fast Match: Display a sequence of 5 (or so) LEDs really fast — perhaps with just a tenth of a second between each LED flash. Then have the user repeat the whole sequence correctly.
Make Your Own: The real fun is in making your own game by mashing-up the suggested projects or challenges together, or creating something completely new!