Build a reaction game the whole family can take part in by Andrew Dawson, Technocamps
Andrew Dawson is a Delivery Officer for Technocamps, he works as part of a team to develop and deliver workshops across North Wales | Twitter: https://twitter.com/Technocamps
Can we bring a family together with some cardboard, foil and computer science? This project shows you how to create an interactive family game by using all of these. Let's get started!
By the end of this section, you will have a button input that will start the game which will show some LED lights after a random amount of time.
The button input coding block allows you to control when the game starts. By combining the pause and random blocks we can make the game less predictable for the players.
One Player Reaction
The single-player game will count the time until the pin is pressed, once the pin is pressed it will show the player their reaction time. A WHILE loop repeats any code inside of the loop if the statement is true.
We can make a variable that will track the amount of time it takes for the players to react. At the start of each round, we reset TimeCount to 0. Within the while loop, we change AND pause the amount of time that is passing by the same value.
To test your game, create a gamepad using cardboard, foil and crocodile clips. When playing the game, always keep one finger on the ground foil and press the foil of your player number to complete the circuit.
Family Game Mode
This section will expand our game to use all the pins to make this a 3 player family game. Using a new variable called playerReaction we can check to see IF a player has pressed a pin. When the button A is pressed, you reset the playerReaction to 0. The WHILE loop will now check if this value is 0. Inside of the WHILE loop, you change the value of playerReaction using an IF block. Using 3 IF blocks, we can check to see if pins 0 / 1 / 2 have been pressed. When a PIN is pressed, you set the variable to the player number and this will make the WHILE loop false and break from the loop.
At the end of your program, you can see which player has the quickest reaction and what their time was.
A Scoring System
What fun is a family game if you can't prove that you beat everyone? In our final section, you will create a scoring system that will show the winner when a score is reached.
Firstly, we will need to create a variable for each of the players e.g. player1. We can use button B to reset all the scores to 0. Within our while loop, you can CHANGE the score each time pin 0 / 1 / 2 is pressed and update the relevant player's score.
To display the player who reaches the score limit, you will need to use an IF block to check each player's score to see if it is EQUAL to 5 (choose your own high score value). THEN text will be displayed to show who the winner is. This check can be done at the end of each round. Can you complete the game to work for all 3 players?