function CheckIfWin () {
if (Slot1.get(LedSpriteProperty.Y) == Slot2.get(LedSpriteProperty.Y) && (Slot2.get(LedSpriteProperty.Y) == Slot3.get(LedSpriteProperty.Y) && (Slot3.get(LedSpriteProperty.Y) == Slot4.get(LedSpriteProperty.Y) && Slot4.get(LedSpriteProperty.Y) == Slot5.get(LedSpriteProperty.Y)))) {
wins = 10
show_credit()
} else if (Slot2.get(LedSpriteProperty.Y) == Slot3.get(LedSpriteProperty.Y) && (Slot3.get(LedSpriteProperty.Y) == Slot4.get(LedSpriteProperty.Y) && Slot4.get(LedSpriteProperty.Y) == Slot5.get(LedSpriteProperty.Y))) {
wins = 4
show_credit()
} else if (Slot1.get(LedSpriteProperty.Y) == Slot3.get(LedSpriteProperty.Y) && Slot3.get(LedSpriteProperty.Y) == Slot4.get(LedSpriteProperty.Y) && Slot4.get(LedSpriteProperty.Y) == Slot5.get(LedSpriteProperty.Y)) {
wins = 4
show_credit()
} else if (Slot1.get(LedSpriteProperty.Y) == Slot2.get(LedSpriteProperty.Y) && (Slot2.get(LedSpriteProperty.Y) == Slot4.get(LedSpriteProperty.Y) && Slot4.get(LedSpriteProperty.Y) == Slot5.get(LedSpriteProperty.Y))) {
wins = 4
show_credit()
} else if (Slot1.get(LedSpriteProperty.Y) == Slot2.get(LedSpriteProperty.Y) && (Slot2.get(LedSpriteProperty.Y) == Slot3.get(LedSpriteProperty.Y) && Slot3.get(LedSpriteProperty.Y) == Slot5.get(LedSpriteProperty.Y))) {
wins = 4
show_credit()
} else if (Slot1.get(LedSpriteProperty.Y) == Slot2.get(LedSpriteProperty.Y) && (Slot2.get(LedSpriteProperty.Y) == Slot3.get(LedSpriteProperty.Y) && Slot3.get(LedSpriteProperty.Y) == Slot4.get(LedSpriteProperty.Y))) {
wins = 4
show_credit()
} else {
music.playTone(330, music.beat(BeatFraction.Quarter))
music.playTone(262, music.beat(BeatFraction.Quarter))
music.playTone(247, music.beat(BeatFraction.Quarter))
music.playTone(220, music.beat(BeatFraction.Half))
ready = true
}
}
function show_credit () {
music.startMelody(music.builtInMelody(Melodies.Ringtone), MelodyOptions.Once)
Credit += wins
I2C_LCD1602.ShowString("Credits: " + convertToText(Credit) + " ", 0, 0)
I2C_LCD1602.ShowString("You win: " + convertToText(wins), 0, 1)
basic.pause(1000)
ready = true
}
let Run5 = false
let Run4 = false
let Run3 = false
let Run2 = false
let Run1 = false
let Slot5: game.LedSprite = null
let Slot4: game.LedSprite = null
let Slot3: game.LedSprite = null
let Slot2: game.LedSprite = null
let Slot1: game.LedSprite = null
let Credit = 0
let ready = false
let wins = 0
pins.setPull(DigitalPin.P1, PinPullMode.PullDown)
wins = 0
let once = false
ready = true
Credit = 20
Slot1 = game.createSprite(0, 0)
Slot2 = game.createSprite(1, 0)
Slot3 = game.createSprite(2, 0)
Slot4 = game.createSprite(3, 0)
Slot5 = game.createSprite(4, 0)
I2C_LCD1602.LcdInit(39)
I2C_LCD1602.BacklightOn()
I2C_LCD1602.ShowString("Credits: " + convertToText(Credit), 0, 0)
music.startMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
basic.forever(function () {
if (Run1) {
for (let index = 0; index < randint(31, 33); index++) {
basic.pause(40)
Slot1.change(LedSpriteProperty.Y, 1)
if (Slot1.get(LedSpriteProperty.Y) == 4) {
basic.pause(40)
Slot1.set(LedSpriteProperty.Y, 1)
}
}
Run1 = false
}
})
basic.forever(function () {
if (once) {
once = false
if (Credit <= 0) {
I2C_LCD1602.ShowString("GAME OVER.... ", 0, 0)
} else {
Credit += -1
Run1 = true
Run2 = true
Run3 = true
Run4 = true
Run5 = true
I2C_LCD1602.ShowString("Credits: " + convertToText(Credit) + " ", 0, 0)
I2C_LCD1602.ShowString(" ", 0, 1)
}
basic.pause(10)
}
if (pins.digitalReadPin(DigitalPin.P1) == 1 && ready == true) {
once = true
ready = false
}
})
basic.forever(function () {
if (Run5) {
for (let index = 0; index < randint(43, 45); index++) {
basic.pause(60)
Slot5.change(LedSpriteProperty.Y, 1)
if (Slot5.get(LedSpriteProperty.Y) == 4) {
basic.pause(60)
Slot5.set(LedSpriteProperty.Y, 1)
}
}
Run5 = false
CheckIfWin()
}
})
basic.forever(function () {
if (Run2) {
for (let index = 0; index < randint(34, 36); index++) {
basic.pause(45)
Slot2.change(LedSpriteProperty.Y, 1)
if (Slot2.get(LedSpriteProperty.Y) == 4) {
basic.pause(45)
Slot2.set(LedSpriteProperty.Y, 1)
}
}
Run2 = false
}
})
basic.forever(function () {
if (Run4) {
for (let index = 0; index < randint(40, 42); index++) {
basic.pause(55)
Slot4.change(LedSpriteProperty.Y, 1)
if (Slot4.get(LedSpriteProperty.Y) == 4) {
basic.pause(55)
Slot4.set(LedSpriteProperty.Y, 1)
}
}
Run4 = false
}
})
basic.forever(function () {
if (Run3) {
for (let index = 0; index < randint(37, 39); index++) {
basic.pause(50)
Slot3.change(LedSpriteProperty.Y, 1)
if (Slot3.get(LedSpriteProperty.Y) == 4) {
basic.pause(50)
Slot3.set(LedSpriteProperty.Y, 1)
}
}
Run3 = false
}
})