SHOW:
|
|
- or go back to the newest paste.
| 1 | let x_winning = 0 | |
| 2 | let score = 0 | |
| 3 | let start = false | |
| 4 | let agent = 0 | |
| 5 | let difficulty = 0 | |
| 6 | let j = 0 | |
| 7 | input.onButtonPressed(Button.A, () => {
| |
| 8 | led.unplot(agent, 4) | |
| 9 | if (agent > 0) {
| |
| 10 | agent += -1 | |
| 11 | } | |
| 12 | led.plot(agent, 4) | |
| 13 | }) | |
| 14 | input.onButtonPressed(Button.B, () => {
| |
| 15 | led.unplot(agent, 4) | |
| 16 | if (agent < 4) {
| |
| 17 | agent += 1 | |
| 18 | } | |
| 19 | led.plot(agent, 4) | |
| 20 | }) | |
| 21 | input.onGesture(Gesture.Shake, () => {
| |
| 22 | if (!(start)) {
| |
| 23 | basic.clearScreen() | |
| 24 | led.stopAnimation() | |
| 25 | } | |
| 26 | start = true | |
| 27 | }) | |
| 28 | j = 0 | |
| 29 | difficulty = 500 | |
| 30 | score = 0 | |
| 31 | start = false | |
| 32 | x_winning = 0 | |
| 33 | agent = 2 | |
| 34 | basic.forever(() => {
| |
| 35 | if (start) {
| |
| 36 | led.plot(agent, 4) | |
| 37 | x_winning = Math.random(5) | |
| 38 | for (let i = 0; i <= 4; i++) {
| |
| 39 | for (let k = 0; k <= 4; k++) {
| |
| 40 | led.plot(k, i) | |
| 41 | } | |
| 42 | led.unplot(x_winning, i) | |
| 43 | if (i == 4) {
| |
| 44 | led.plot(agent, 4) | |
| 45 | if (agent != x_winning) {
| |
| 46 | basic.showString("Game over! Score", 75)
| |
| 47 | basic.showNumber(score) | |
| 48 | basic.pause(2000) | |
| 49 | control.reset() | |
| 50 | } | |
| 51 | } | |
| 52 | basic.pause(difficulty) | |
| 53 | for (let l = 0; l <= 4; l++) {
| |
| 54 | led.unplot(l, i) | |
| 55 | } | |
| 56 | if (i == 4) {
| |
| 57 | led.plot(agent, 4) | |
| 58 | } | |
| 59 | } | |
| 60 | score += 1 | |
| 61 | if (difficulty > 75) {
| |
| 62 | difficulty = difficulty - 20 | |
| 63 | } | |
| 64 | } else {
| |
| 65 | basic.showString("Shake it off!", 70)
| |
| 66 | } | |
| 67 | }) |