-
Notifications
You must be signed in to change notification settings - Fork 15
/
CC cpx1
90 lines (90 loc) · 2.21 KB
/
CC cpx1
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
function checkGuess (guess: number) {
if (guess == SEQUENCE[sequenceIndex]) {
console.log("Correct")
if (SEQUENCE.length == sequenceIndex + 1) {
light.showRing(
`green green green green green green green green green green`
)
if (list.length == 10) {
light.showRing(
`green green green green green green green green green green`
)
console.log("You won!")
music.jumpUp.play()
}
control.waitMicros(1000000)
addValue()
showAll()
} else {
sequenceIndex += 1
}
} else {
console.log("Wrong")
light.showRing(
"red red red red red red red red red red"
)
music.wawawawaa.play()
list = []
}
}
function showValue (num: number) {
if (num == 1) {
light.showRing(
`black black black black black blue blue black black black`
)
music.baDing.play()
}
if (num == 2) {
light.showRing(
`black black black black black black black black red red`
)
music.baDing.play()
}
if (num == 3) {
light.showRing(
`green green black black black black black black black black`
)
music.baDing.play()
}
if (num == 4) {
light.showRing(
`black black black pink pink black black black black black`
)
music.baDing.play()
}
}
function addValue () {
SEQUENCE.push(Math.randomRange(1, 4))
console.log(SEQUENCE)
}
input.pinA1.onEvent(ButtonEvent.Down, function () {
showValue(1)
checkGuess(1)
})
input.pinA4.onEvent(ButtonEvent.Down, function () {
showValue(3)
checkGuess(3)
})
input.pinA3.onEvent(ButtonEvent.Down, function () {
showValue(2)
checkGuess(2)
})
input.pinA7.onEvent(ButtonEvent.Down, function () {
showValue(4)
checkGuess(4)
})
function showAll () {
for (let value of SEQUENCE) {
showValue(value)
control.waitMicros(700000)
}
sequenceIndex = 0
}
let list: number[] = []
let sequenceIndex = 0
let SEQUENCE: number[] = []
SEQUENCE = []
for (let i = 0; i < 4; i++) {
addValue()
}
showAll()