-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnvironmentBuilder.js
35 lines (32 loc) · 1.13 KB
/
EnvironmentBuilder.js
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
const { Environment } = require("./Environment/environment");
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function build(environment) {
let isOn = true;
let trafficLight = environment.addTrafficLight();
let trafficLightPedestrian = environment.addPedestrianTrafficLight();
environment.setStartState(() => {
trafficLight.turnLightOn('red');
trafficLight.turnLightOff('yellow');
trafficLight.turnLightOff('green');
trafficLightPedestrian.turnLightOn('green');
trafficLightPedestrian.turnLightOn('red');
});
let Button0 = environment.addButton(async () => {
//Button press
if (isOn) {
trafficLight.turnLightOn('green');
trafficLight.turnLightOff('red');
trafficLight.turnLightOn('yellow');
await environment.pause(1000);
trafficLight.turnLightOff('yellow');
}
else{
trafficLight.turnLightOff('green');
trafficLight.turnLightOn('red');
}
isOn = !isOn;
});
}
exports.build = build;