Introduction: Memory Puzzle Game Using a BBC MicroBit
If you dont know what a BBC MicroBit is, it is basically a really small device that you can program to have inputs and outputs. Kindof like an Arduino, but more fleshed out.
What I really loved about the MicroBit was that it has two built in input buttons and a 5 x 5 led matrix!
So, i thought, why not create a simple to make, but hard to play memory puzzle game!
ps: If you dont want to code, i will attatch the .hex file to directly upload to the MicroBit.
All you need is
1) BBC MicroBit
2) Laptop or PC to program the Microbit
3) Some patience!
Step 1: Create a Project Using the Online Block Based Coding Platform, Makecode.
Go to https://makecode.microbit.org/ and create a new project. This is where we will be creating the code for our game.
Here is my attached code:
Step 2: What Is the Game?
Well, think of this as a two button Simon Says game.
The screen will show a series of combination of A and B and the player has to memorize the sequence and then input it using the A and B button on the MicroBit.
To make the game progressively harder, we will increase the number of letters by 2 each round and also reduce the time that each letter stays on screen.
Step 3: It's CODING TIME!!!
Well, not quite. As the makercode website is really beginner friendly and has something called block coding. Here, we just take blocks, and combine with more blocks! Amazing , RIght!
Well first we need to understand what we need to code for.
In the start blocks, we will add the global variables, and change the brightness if needed.
"level"=1, "Delay" = 500, "set.score" = 0.
We will use the score functionality to keep track of the score.
In our game, the first step is to pick a random letter : A or B.
We can do this by first selecting randomly between 1 and 2 and then assigning A to 1 and B to 2 and storing in a variable "AB".
now, for each time we select A or B, we will display it on the screen for a period of "Delay" ms.
this is in a variable as per level, we will decrease the "Delay" by 50 ms, till it is 50 ms, by starting the level 1 with 500 ms.
Step 4: Repeating This for Each Level With Increment of Two Letters
We achieve this by repeating the block "Length" number of times where
Length = 2 + (level - 1 ) x 2.
What this does is, if we have level = 1 at the start of the loop, and we increase level by 1, our length per level becomes 2,4,6,8 and so on.
Now, after we generate a letter, we want to store it too. So, we set a blanl string "Question" as "Question" + "AB"
This will give us the entire string that we generated letter by letter.
we also need some kind of indication to see if this loop has ended or not so that we can get the answer from the player. we do this by setting a variable called "cond" in the beginning as 0, and then changing it to 1 as the loop ends. simple!
we also need to add a break condition to the loop. If the game is over, then we need it to break out of the loop and not generate more letters.
We will put all of this in a function called "Generate", add some starting image, throw in an image over there, add a ? in the end, and boom!
Step 5: Getting the Answer!
When the user presses A or B, we need to store that information and make a string "Answer" so that we can compare it to the "Question".
We do this by getting the input only when "cond" = 1 to prevent the player from entering the answer as the "Question" is being displayed.
We then combine the input into a string as save it a "Answer".
Step 6: Checking the Answer!
Now, we just compare the "Question" we generated to the "Answer" that was given by the player.
If they match, then we go to the next level, else....GAME OVER!!!
And we display the score at the end.
This also we will keep in a function called "Check" that will be called if "cond" = 1 when getting an input, else....GAME OVER!
Step 7: Done!
Now, all we need to do is upload the code to the MicroBit, and then test everyone you know!
Participated in the
Puzzles Speed Challenge