yesterday I got into coding micro:bit, the problem I am having, is that when I lose the "snake" game, the "jim face" starts blinking, even though it doesn't do that when I first start the program, here is my program ( I do not want tips on how to shorten the code and make it better - that is up to me to find out - I only want you to answer the question I have) I have coded this on makecode.microbit.org or something like that; sorry if code format is wrong, I am new here:
let happy_score = 5
let food_counter = 5
let debounce_jim = 0
let debounce = 0
function jim(expression: string = "meh"){
basic.clearScreen()
debounce = 1
console.log("jim")
input.onButtonPressed(Button.A,function(){
if (food_counter > 0){
food_counter -= 1
happy_score += 1
}
})
while (debounce_jim == 0){
input.onButtonPressed(Button.AB, function () {
debounce = 0
debounce_jim = 1
snake()
})
pause(0)
happy_score -= 1
if (food_counter < 1){
basic.showNumber(0)
}
if (food_counter < 0){
food_counter = 0
}
if (happy_score > 2) {
expression = "happy"
}else if(happy_score <= 2 && happy_score >0){
expression = "meh"
} else {
expression = "sad"
}
if (expression == "happy"){
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# . . . #
. # # # .
`)
}
if (expression == "meh"){
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# # # # #
. . . . .
`)
}
if (expression == "sad"){
basic.showLeds(`
. # . # .
. . . . .
. # # # .
# . . . #
. . . . .
`)
}
}
}
function snake() {
let player = game.createSprite(2,2)
let food = game.createSprite(1,1)
let score = 0
food.setBlink(100)
console.log("snake")
while (debounce == 0){
if (player.isTouchingEdge()){
debounce = 1
debounce_jim = 0
console.log("debounce")
player.off()
food.off()
game_end(score)
}
if (player.isTouching(food)){
score += 1
food_counter += 1
food.setX(randint(1,3))
food.setY(randint(1,3))
}
pause(1000)
player.move(1)
input.onButtonPressed(Button.A, function(){
player.changeDirectionBy(90)
})
input.onButtonPressed(Button.B, function () {
player.changeDirectionBy(-90)
})
}}
function game_end(score: number){
basic.showNumber(score)
console.log("game end")
pause(100)
basic.showString("||")
jim(null)
}
jim(null)