Brain Game
Brain Game
Introduction
In this project you’ll learn how to create a times table quiz, in which you have to
get as many answers correct as you can in 30 seconds.
Activity Checklist
Start a new Scratch project, and delete the cat sprite so that your project
is empty. You can find the online Scratch editor at jumpto.cc/scratch-
new.
Choose a character and a backdrop for your game. You can choose any
you like! Here’s an example:
1
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Create 2 new variables called number 1 and number 2 . These variables
will store the 2 numbers that will be multiplied together.
when
clicked
You can then ask the player for the answer, and let them know if they
were right or wrong.
2
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
when
clicked
wait
answer =
if number 1 * then
number 2
else
Test your project fully, by answering one question correctly and one with
the wrong answer.
Add a forever loop around this code, so that the player is asked lots of
questions.
3
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
respond to the player’s answer?
Activity Checklist
Create a new ‘Play’ button sprite, which your player will click to start a
new game. You can draw it yourself, or edit a sprite from the Scratch
library.
4
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Add this code to your new button.
This code shows the play button when your project is started. When the
button is clicked, it is hidden and then broadcasts a message that will
start the game.
You’ll need to edit your character’s code, so that the game starts when
they receive the start message, and not when the flag is clicked.
Replace the when flag clicked code with when I receive start .
Click the green flag and then click your new play button to test it. You
should see that the game doesn’t start until the button is clicked.
Did you notice that the timer starts when the green flag is clicked, and
not when the game starts?
5
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Can you fix this problem?
Click on the stage, and replace the stop all block with an end message.
You can now add code to your button, to show it again at the end of
each game.
when I receive
end ▼
show
You’ll also need to stop your character asking questions at the end of
each game:
when I receive
end ▼
Test your play button by playing a couple of games. You should notice
6
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
that the play button shows after each game. To make testing easier, you
can shorten each game, so that it only lasts a few seconds.
set time ▼ to 10
You can even change how the button looks when the mouse hovers
over it.
when
clicked
show
forever
else
7
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
backdrops.
You can also show and hide your character, and even show
and hide your timer by using these blocks:
Create a new sprite called ‘Result’, containing both a ‘tick’ and a ‘cross’
costume.
8
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Change your character’s code, so that instead of telling the player how
they did, it broadcasts correct and wrong messages instead.
You can now use these messages to show the ‘tick’ or ‘cross’ costume.
Add this code to your new ‘Result’ sprite:
9
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Test out your game again. You should see a tick whenever you get a
question correct, and a cross whenever you get one wrong!
Have you noticed that the code for when I receive correct and when I receive
wrong is nearly identical? Let’s create a function to make it easier for you
to make changes to your code.
On your ‘Result’ sprite, click More Blocks , and then ‘Make a Block’.
Create a new function called animate .
10
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
You can then add the animation code into your new animation function,
and then just use the function twice:
Now, if you want to show the tick and the cross for a longer or shorter
time, you only need to make one change to your code. Try it!
Instead of just showing and hiding the tick and the cross, you could
change your animation function, so that the graphics fade in.
11
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
define animate
show
repeat 25
hide
12
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Challenge: Sound and music
Can you add sound effects and music to your game? For
example:
13
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
when I receive
start ▼
set time ▼ to 30
time =
repeat until
0
wait 1 secs
change time ▼ by -1
broadcast end ▼
You may also need a ‘Back’ button to take you to the main
menu.
14
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409
Save your project
15
This content is for non-commercial use only and we reserve the right at any time to withdraw permission for use. © 2012-2016 Raspberry Pi Foundation. UK
Registered Charity 1129409