Introduction-to-Computer-Engineering
/
migrating-microbit-programming-from-blocks-to-javascript-nekao
Public
generated from ivogeorg/starter-migrating-from-blocks-to-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6LivePetGame.js
58 lines (58 loc) · 1.56 KB
/
6LivePetGame.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
input.onButtonPressed(Button.AB, function () {
index = 0
yindex = 0
if (health > 0) {
for (let yindex2 = 0; yindex2 <= 4; yindex2++) {
for (let xindex = 0; xindex <= 4; xindex++) {
led.plot(xindex, yindex2)
basic.pause(1)
led.unplot(xindex, yindex2)
basic.pause(1)
}
}
basic.showNumber(health)
basic.showIcon(IconNames.Silly)
}
})
input.onGesture(Gesture.Shake, function () {
hand = Math.randomRange(0, 3)
if (health > 0) {
if (hand == 0) {
health += -100
basic.showIcon(IconNames.Surprised)
} else if (hand == 1) {
health += -1
basic.showIcon(IconNames.Asleep)
} else if (hand == 2) {
health += -50
basic.showIcon(IconNames.Angry)
} else {
health += -10
basic.showIcon(IconNames.Sad)
}
}
})
let hand = 0
let yindex = 0
let index = 0
let health = 0
health = 100
basic.showIcon(IconNames.Happy)
basic.forever(function () {
if (input.buttonIsPressed(Button.B)) {
basic.showIcon(IconNames.Happy)
health = 100
}
if (health > 0) {
if (input.buttonIsPressed(Button.A)) {
while (input.buttonIsPressed(Button.A)) {
health += 10
basic.showIcon(IconNames.Heart)
basic.showIcon(IconNames.SmallHeart)
}
basic.showIcon(IconNames.Happy)
}
} else {
basic.showIcon(IconNames.Skull)
}
})