This repository has been archived by the owner on Aug 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-memory-game.ts
117 lines (112 loc) · 3.32 KB
/
image-memory-game.ts
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
let progress = 0
let pattern: number[] = []
let listening = false
listening = false
game.setScore(1)
// Loop the game for 3 rounds
while (game.score() <= 3) {
// Display the current round
basic.showString("R" + game.score())
basic.pause(500)
// Generate a random pattern and display the image pattern
pattern = [Math.randomRange(1, 5), Math.randomRange(1, 5), Math.randomRange(1, 5), Math.randomRange(1, 5), Math.randomRange(1, 5)]
for (let value of pattern) {
if (value == 1) {
basic.showIcon(IconNames.Heart)
basic.pause(100)
} else if (value == 2) {
basic.showIcon(IconNames.Duck)
basic.pause(100)
} else if (value == 3) {
basic.showIcon(IconNames.Giraffe)
basic.pause(100)
} else if (value == 4) {
basic.showIcon(IconNames.Ghost)
basic.pause(100)
} else if (value == 5) {
basic.showIcon(IconNames.Scissors)
basic.pause(100)
}
basic.clearScreen()
basic.pause(100)
}
basic.pause(200)
basic.clearScreen()
basic.showString("Go!")
// Listen for the user's inputs
listening = true
progress = 0
while (listening) {
if (tinkercademy.ADKeyboard(ADKeys.A, AnalogPin.P0)) {
if (pattern[progress] == 1) {
progress += 1
basic.clearScreen()
basic.pause(20)
basic.showIcon(IconNames.Heart)
} else {
game.gameOver()
}
} else if (tinkercademy.ADKeyboard(ADKeys.B, AnalogPin.P0)) {
if (pattern[progress] == 2) {
progress += 1
basic.clearScreen()
basic.pause(20)
basic.showIcon(IconNames.Duck)
} else {
game.gameOver()
}
} else if (tinkercademy.ADKeyboard(ADKeys.C, AnalogPin.P0)) {
if (pattern[progress] == 3) {
progress += 1
basic.clearScreen()
basic.pause(20)
basic.showIcon(IconNames.Giraffe)
} else {
game.gameOver()
}
} else if (tinkercademy.ADKeyboard(ADKeys.D, AnalogPin.P0)) {
if (pattern[progress] == 4) {
basic.clearScreen()
basic.pause(20)
basic.showIcon(IconNames.Ghost)
} else {
game.setScore(0)
}
} else if (tinkercademy.ADKeyboard(ADKeys.E, AnalogPin.P0)) {
if (pattern[progress] == 5) {
basic.clearScreen()
basic.pause(20)
progress += 1
basic.showIcon(IconNames.Scissors)
} else {
game.gameOver()
}
}
// Has the user gotten the entire sequence correct?
if (progress >= 5) {
listening = false
game.addScore(1)
}
basic.pause(50)
}
}
// The user has beaten the game. Display the victory screen!
basic.showLeds(`
# # # # #
# # # # #
. # # # .
. . # . .
. # # # .
`)
basic.pause(200)
basic.clearScreen()
basic.pause(200)
basic.showLeds(`
# # # # #
# # # # #
. # # # .
. . # . .
. # # # .
`)
basic.pause(500)
basic.showString("Winner!")