功能
- 開機時顯示狗臉榔袋,年齡為0,精力為0
- 按A鍵喂食增長精力直到10,小于6的時候顯示哭臉睛约,大于6顯示笑臉,到10顯示心形
- 喂飽之后(即精力大于6)每
年齡 * 10
秒長大一歲
- 按B鍵查看年齡
- 按A+B查看精力
代碼
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