During a gold rush, gold miners use different techniques to find traces of gold hidden in the ground. One technique that miners use is gold panning. It consists of scooping some gravels and clear water in a pan which is gently agitated until small gold nuggets sinks to the bottom of the pan and can be handpicked.
For this challenge the pan will be the micro:bit. A LED light will represent a gold nugget. The aim is to tilt the micro:bit slightly to detect and pick up the gold nugget.
We will be using the built-in accelerometer sensor to detect in which direction the microbit is being tilted.
Every time the player (miner) will pick a gold nugget a new one will randomly appear on the 5 x 5 LED screen.
Use the BBC microbit website to complete the code:
Checking the code above answer the following questions:
- Can you identify the block of code used for the micro:bit to detect if it has been tilted to the left?
- Can you identify the block of code used for the micro:bit to know when the miner has picked up a gold nugget?
- Can you explain how does the micro:bit decide to stop the game by running the last block to display the Game Over message?
Change this game to use a timer. The game should last exactly 1 minute. Everytime the player picks up a gold nugget their score should increment by 1. After 1 minute, the game should stop and display the total score.
Ideas to get started
- You could use a variable called “timer” and set it to 60000ms.
- You could decrement your timer variable when the game is paused.
- You will have to change the condition of your while loop: Instead of while score<10, use while timer>0.
- Make sure that you display the final score at the end of the game.