-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrouce.ts
More file actions
113 lines (97 loc) · 2.27 KB
/
srouce.ts
File metadata and controls
113 lines (97 loc) · 2.27 KB
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
// Micro:Bit Environment. Edit and Compile at makecode.microbit.org
let expectedInput = ""
let randomValue = 0
let gameState = 0
let currentInstructions: string[] = []
let currentInstructionIndex = 0
let score = 0
function gameStart() {
score = 0
currentInstructions = []
currentInstructionIndex = 0
basic.showLeds(`
. . . . .
. # . # .
# # . # #
. # . # .
. . . . .
`)
}
input.onButtonPressed(Button.A, function () {
if (gameState != 2) {
return
}
expectedInput = currentInstructions[currentInstructionIndex]
if (expectedInput == "B") {
gameState = 3
} else {
currentInstructionIndex += 1
if (currentInstructionIndex == currentInstructions.length) {
score = score + 1
gameState = 1
}
}
})
input.onButtonPressed(Button.AB, function () {
gameState = 1
})
input.onButtonPressed(Button.B, function () {
if (gameState != 2) {
return
}
expectedInput = currentInstructions[currentInstructionIndex]
if (expectedInput == "A") {
gameState = 3
} else {
currentInstructionIndex += 1
if (currentInstructionIndex == currentInstructions.length) {
score = score + 1
gameState = 1
}
}
})
function gameOver() {
basic.showString("GG")
basic.showNumber(score)
basic.pause(500)
gameState = 0
}
function showInstructions() {
randomValue = Math.randomRange(0, 1)
if (randomValue == 0) {
currentInstructions.push("A")
} else if (randomValue == 1) {
currentInstructions.push("B")
}
for (let i = 0; i < currentInstructions.length; i++) {
basic.showString(currentInstructions[i])
basic.pause(200)
basic.clearScreen()
basic.pause(100)
}
currentInstructionIndex = 0
gameState = 2
}
function waitForPlayerInput() {
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`)
}
basic.forever(function () {
if (gameState == 0) {
gameStart()
}
if (gameState == 1) {
showInstructions()
}
if (gameState == 2) {
waitForPlayerInput()
}
if (gameState == 3) {
gameOver()
}
})