Microbit 开发一个电子宠物

2019-05-29  本文已影响0人  _黑冰_

功能

代码

let days = 0
let full = 0
let age = 0
input.onButtonPressed(Button.A, function () {
    if (full < 10) {
        full += 1
    }
})
input.onButtonPressed(Button.B, function () {
    basic.showNumber(age)
})
input.onButtonPressed(Button.AB, function () {
    basic.showNumber(full)
})
basic.showLeds(`
    . . . . .
    # # . # #
    # # . # #
    . . . . .
    . # # # .
    `)
age = 0
full = 0
basic.forever(function () {
    if (full < 6) {
        basic.showIcon(IconNames.Sad)
    } else if (full < 10) {
        basic.showIcon(IconNames.Happy)
    } else {
        basic.showIcon(IconNames.Heart)
    }
    if (full >= 6) {
        days = age * 10000
        game.startCountdown(days)
        age += 1
    }
})


在线编辑器

microbit editor

上一篇 下一篇

猜你喜欢

热点阅读