forked from neonerz/johnson_build_challenge_ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
54 lines (48 loc) · 1.43 KB
/
main.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
//ENUMS
enum Four_Axis {
//% block="forward"
Forward,
//% block="back"
Back,
//% block="left"
Left,
//% block="right"
Right
}
//GLOBAL VARIABLES
const communicationsTimeout = 75;
//% block="Johnson Build Challenge" weight=200 color=#0B3D91 icon="\uf186"
namespace johnsonBuildChallenge {
/**
* This function moves the Agent
* in four directions
*/
//% block = "agent move %d by %n"
export function agent_move(d: Four_Axis, n: number): void {
for (let i = 0; i < n; i++) {
switch (d) {
case Four_Axis.Forward:
player.execute("scoreboard players set .output global 1")
break;
case Four_Axis.Back:
player.execute("scoreboard players set .output global 2")
break;
case Four_Axis.Left:
player.execute("scoreboard players set .output global 3")
break;
case Four_Axis.Right:
player.execute("scoreboard players set .output global 4")
break;
}
loops.pause(communicationsTimeout)
}
}
/**
* This function launches the Agent
*/
//% block = "agent launch"
export function launch_agent(): void {
player.execute("scoreboard players set .output global 5")
loops.pause(communicationsTimeout)
}
}