Microbit
Advanced
60 mins
Teacher/Student led
150 points
What you need:
Chromebook/Laptop/PC
Microbit

Microbit Hot Potatoe

Embark on an exciting journey to create your own 'Hot Potato' game using Microbit. You'll learn to create a new project, establish a variable for a countdown, and code an animation. The game concludes with a skull icon and sound, indicating the end of the countdown. Enjoy playing with friends!
Learning Goals Learning Outcomes Teacher Notes Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    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()
    })

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    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