Let's make a game of Simon Says! Simon Says is a memory game in which the player will be given a color. They have to repeat that color back.
If they get it right a color is added to the sequence, so they now have to remember 2 colors, then 3, then 4 etc. the game stops as soon as the player makes a mistake.
Exercise
In this first part of the Simon Says adventure, we'll let the computer pick a random color and add it to a list.
Make 2 lists First, make a list called colors
and fill it with the colors red, yellow, green and blue.
Then make a list called simon_sequence
. This list will be used as the answer.
At the start of the game this lists need to be empty. unfortunately, we can't create an empty list (yet), so we'll fill it with the words 'empty' and 'list' and we'll remove them from the list immediately.
Create a function that adds a color to the sequence Now that we have an empty list called simon_sequence, we can start filling it with random colors.
We do that with a function, so we can call it everytime there's a new level in our game. Create a function called add_random_color
.
Then create the variable random_color and set it to a random color. Next, add this random color to the simon_sequence.
Create a function that shows the simon_sequence Start by naming the new function show_simon_sequence
with level
as an argument. Now we want to show as many colors as the level we are in (in level 1 you see 1 color, in level 2 you see 2 colors etc).
So we repeat level
times, to print the simon_sequence[i]
. Each time a color is shown, wait for 1 second and then clear the screen.
Test your program Before you go to the next level, test if the functions are working by calling both of the functions. If they're working you should see a random color in your output screen.
Remove this testing part of your code, copy the code and continue to the next tab to learn more about the simon says game!
# Make 2 lists
colors = _
_ = ['empty', 'list']
remove _ from simon_sequence
remove _
# Create a function that adds a color
_ add_random_color
_
add _
# Create a function that shows the simon_sequence
define _
for i in range 1 to _
print _
_
_
# Test your program
call _
call show_simon_sequence with 1