Microbit
Advanced
30 mins
150 points
What you need:
  • Chromebook/Laptop/PC

Microbit Hot Potatoe

Don't be the one left holding the Microbit when the countdown stops! In this project we make the Microbit into a Hot Potatoe game.

1 - Create a new project

Go to the https://makecode.microbit.org website and create a new project.

2 - Create a variable

In the game there will be a countdown of a random number of seconds. Create a variable called seconds, we will use this to store the amount of seconds.

Once you've created the variable, add the following code to set the amount of seconds to a number between 4 and 20 when you press the A button.

input.onButtonPressed(Button.A, function () {
    seconds = randint(4, 20)
})

3 - Countdown

Now add the following new code to subtract 1 from the seconds variable until it is equal to 0.

let seconds = 0
input.onButtonPressed(Button.A, function () {
    seconds = randint(4, 20)
    while (seconds > 0) {
        seconds += -1
        basic.pause(1000)
    }
})

4 - Animation

Add the following new code to show an animation while the countdown is on.

Note that each icon takes 600 milliseconds to display, so each 'second' in the game is actually 2.2 seconds (600 + 600 + 1,000 = 2,200 milliseconds).

let seconds = 0
input.onButtonPressed(Button.A, function () {
    seconds = randint(4, 20)
    while (seconds > 0) {
        seconds += -1
        basic.pause(1000)
        basic.showIcon(IconNames.Diamond)
        basic.showIcon(IconNames.SmallDiamond)
    }
})

5 - Game over

Finally add the following new code to show the skull icon and play a sound when the countdown reaches 0.

let seconds = 0
input.onButtonPressed(Button.A, function () {
    seconds = randint(4, 20)
    while (seconds > 0) {
        seconds += -1
        basic.pause(1000)
        basic.showIcon(IconNames.Diamond)
        basic.showIcon(IconNames.SmallDiamond)
    }
    basic.showIcon(IconNames.Skull)
    soundExpression.sad.play()
})

Join our club 😃

To view the remaining 1 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more