Memory Game part 1
Can you remember the correct sequence and repeat it? How many levels can you get correct?! This is a large project so it's broken into 2 parts.
1 - Introduction
In this project we are going to try and recreate the classic Simon Says game where you need to remember and repeat the colours in the right order.
2 - Create a new Scratch project
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
3 - Draw the pad sprite
We need a pad sprite that has a large black circle with 4 smaller circles inside it. This sprite should have 5 costumes:
- a 'blank' costume with none of the lights on.
- a 'red' costume with the red light on.
- a 'blue' costume with the blue light on.
- a 'green' costume with the green light on.
- a 'yellow' costume with the yellow light on.
To create the pad sprite you have two options:
1.) Upload the sprite
Download the sprite included with this step called 'scmemg pad.sprite3' and then upload it into your project. This has the 5 costumes already setup.
2.) Create you own sprite
Create a new sprite and draw a large black circle with 4 smaller circles inside it. The 4 smaller circles should be red, blue, green and yellow.
In the 'blank' costume make sure the small colour circles aren't too bright, so they look like they're off. Then duplicate the blank costume 4 times. Edit these copies of the blank costume and rename them 'red', 'blue', 'green' and yellow and make the colour of each of their circles brighter so that each one has one colour turned on (for example the 'red' costume should just have the red light turned on).
You can create your own sprites using the sprite editor. To create a new sprite put your mouse over the Choose a Sprite button and then click on the paintbrush.
This create a blank sprite and will open the sprite editor where you can use the tools to create your sprite. You can even create extra costumes for your sprite!
Tip: give your sprite a name so that you can recognise it in the code blocks.
4 - Create some variables and lists
We will need 3 variables and 2 lists in our project.
Create the following variables.
- level - this will store the level of the round the player is playing.
- colour - this will store a random number between 1 and 4 (1 = red, 2 = blue, 3 = green, 4 = yellow).
- x - this is a counter variable, we will use it to go through the items in the lists.
Create the following lists.
- sequence - this list will store the sequence of the colours in the round. For example in level 3 the sequence might be red, green, red. So we would have 3 items in our 'sequence' list (1, 3, 1 for red, green, red).
- answer - this list will store the players answer. As they click their chosen colours it will add their selection to the answer list. For example if the player clicked blue, red, yellow, this would store 2, 1, 4 as the items in the 'answer' list.
You can leave all the variables and lists to display in the stage area for the moment, this will help you see how the code is working.
In the Variables palette, create a new variable by clicking the 'Make a List' button.
Once you click this button a box will appear asking what you want to call your list. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of top scores in a game, you would create a list called 'top scores'.
5 - Create some custom blocks
Create the following custom blocks.
- red - this will have the code to display the red circle and play the musical note A.
- blue - this will have the code to display the blue circle and play the musical note G.
- green - this will have the code to display the green circle and play the musical note C.
- yellow - this will have the code to display the yellow circle and play the musical note D.
- play round - this will have the code to play a round. It will have a number input called 'number' that will allow us to pass in what round we want to play (we will pass the 'level' variable into it).
You can create your own custom blocks and give them their own instructions (code). To create a custom block follow these steps:
- Go to the 'My Blocks' toolbox
- Click the 'Make a Block' button
- Give your block a name
- If you wish you can pass variables/inputs into your blocks
- Click on the 'OK' button
A 'Define My Block Name' will appear in the code area. You can add your code underneath this and then use the My Block Name block in the 'My Blocks' toolbox anytime you wish to run that code.
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu