-
Notifications
You must be signed in to change notification settings - Fork 0
/
levels.ts
48 lines (43 loc) · 1.08 KB
/
levels.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
//% color=#20bf6b weight=100 icon="\uf0ae"
namespace levels {
let currentLevel: number = 1;
const levels: Array<() => void> = [];
/**
Restart the current level
**/
//% block
export function restartLevel() {
startLevel(currentLevel);
}
/**
Start the next level (increment level by one)
**/
//% block
export function startNextLevel() {
startLevel(currentLevel + 1);
}
/**
Change the current level that is playing
@param l the level number
**/
//% block
//% l.defl=1
export function startLevel(l: number = 1) {
currentLevel = l;
const handler = levels[l];
if (handler) {
handler();
} else {
console.error("ERROR: No 'on start level' block found for level " + l);
}
}
/**
Define the code to run on the start of each level
@param l the level number
**/
//% block="on start level $l"
//% l.defl=1
export function onStartLevel(l: number = 1, handler: () => void): void {
levels[l] = handler;
}
}