function endofgame () { endgamecount += 1 if (endgamecount >= 3) { endgame = true blast() basic.showLeds(` . . . . . . # . # . . . . . . . # # # . # . . . # `) basic.pause(1000) basic.clearScreen() basic.showNumber(hit) basic.pause(5000) basic.clearScreen() } else { basic.clearScreen() blast() gun = 2 led.plot(gun, 4) basic.pause(1000) } } input.onButtonPressed(Button.A, function () { if (endgame == false) { if (gun > 0 && gun <= 4) { led.unplot(gun, 4) gun += -1 led.plot(gun, 4) } else { gun = 0 led.plot(gun, 4) } } }) input.onButtonPressed(Button.AB, function () { if (endgame == false) { fire = true missile = 4 while (fire) { if (missile > 0 && missile < 5) { missile += -1 if (!(led.point(gun, missile))) { led.plot(gun, missile) basic.pause(50) led.unplot(gun, missile) } else { led.toggle(gun, missile) led.unplot(rainstart, index) hit += 1 rainstart = 0 missile += 4 fire = false index = 4 } } else { missile += 4 fire = false } } led.plot(gun, 4) } }) input.onButtonPressed(Button.B, function () { if (endgame == false) { if (gun >= 0 && gun < 4) { led.unplot(gun, 4) gun += 1 led.plot(gun, 4) } else { gun = 4 led.plot(gun, 4) } } }) input.onGesture(Gesture.Shake, function () { led.plot(gun, 4) Initialize() }) function Initialize () { basic.clearScreen() gun = 2 hit = 0 missile = 4 fire = false endgame = false endgamecount = 0 led.plot(gun, 4) basic.pause(1000) } function blast () { basic.showLeds(` . . . . . . . . . . . . . . . . . # . . . # . # . `) basic.showLeds(` . . . . . . . . . . . . # . . . # . # . # . . . # `) basic.showLeds(` . . . . . . . # . . # . . . # . . . . . . . . . . `) basic.showLeds(` . . # . . . . . . . . . . . . . . . . . . . . . . `) basic.showLeds(` . . . . . . . . . . . . . . . . . . . . . . . . . `) } let index = 0 let rainstart = 0 let missile = 0 let fire = false let hit = 0 let endgame = false let endgamecount = 0 let gun = 0 Initialize() basic.forever(function () { if (endgame == false) { rainstart = randint(0, 5) for (let index2 = 0; index2 <= 4; index2++) { led.plot(rainstart, index2) basic.pause(250) if (led.point(rainstart, index2 + 1)) { endofgame() index2 = 4 } else { led.unplot(rainstart, index2) } } } })