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 path12Final.js
145 lines (145 loc) · 3.57 KB
/
12Final.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
input.onGesture(Gesture.Shake, function () {
hand = Math.randomRange(0, 3)
if (health > 0) {
if (hand == 0) {
health += -2
} else if (hand == 1) {
health += -1
} else if (hand == 2) {
health += -50
} else {
health += -10
}
} else {
health = 1
}
})
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
decimal += -1
} else if (receivedNumber == 1) {
decimal += 1
} else if (receivedNumber == 2) {
decimal += 2
} else {
decimal += 3
}
})
let yindex = 0
let index = 0
let decimal = 0
let hand = 0
let health = 0
health = 1
radio.setGroup(1)
let text_list = ["nice", "great", "plant lives"]
basic.forever(function () {
if (input.buttonIsPressed(Button.B)) {
index = 0
yindex = 0
if (health >= 1) {
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)
let random = Math.randomRange(0, text_list.length)
basic.showString(text_list[random])
} else {
health = 1
}
} else {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
}
})
basic.forever(function () {
if (health >= 1) {
if (input.buttonIsPressed(Button.A)) {
while (input.buttonIsPressed(Button.A)) {
led.toggle(1, 0)
led.toggle(3, 0)
basic.pause(250)
led.toggle(1, 1)
led.toggle(3, 1)
basic.pause(1000)
health += 0.25
}
} else {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
}
} else {
health = 1
}
})
basic.forever(function () {
if (input.buttonIsPressed(Button.AB)) {
health = 1
}
if (health >= 1) {
if (health >= 1) {
led.plot(2, 4)
led.setBrightness(14)
}
if (health >= 2) {
led.plot(2, 3)
led.setBrightness(71)
}
if (health >= 3) {
led.plot(3, 2)
led.setBrightness(70)
}
if (health >= 4) {
led.plot(1, 2)
led.setBrightness(108)
}
if (health >= 5) {
led.plot(4, 1)
led.setBrightness(143)
}
if (health >= 6) {
led.plot(0, 1)
led.setBrightness(155)
}
if (health >= 7) {
led.plot(2, 2)
led.setBrightness(182)
}
if (health >= 8) {
led.plot(2, 1)
led.setBrightness(221)
}
if (health >= 9) {
led.plot(2, 0)
led.setBrightness(255)
}
} else {
basic.showIcon(IconNames.Skull)
}
})
basic.forever(function () {
if (input.isGesture(Gesture.ScreenDown) && input.buttonIsPressed(Button.A)) {
radio.sendNumber(2)
}
if (input.isGesture(Gesture.ScreenDown)) {
radio.sendNumber(1)
}
if (input.buttonIsPressed(Button.B) && input.isGesture(Gesture.ScreenDown)) {
radio.sendNumber(0)
}
})