-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotelSimulator.js
72 lines (55 loc) · 2.08 KB
/
HotelSimulator.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
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
{
init: function(elevators, floors) {
var upPressed = [];
var downPressed = [];
var internallyPressed = [];
elevators.forEach(function(elevator){
elevator.on("floor_button_pressed", function(floorNum) {
if(!internallyPressed.contains(floorNum)){
internallyPressed.push(floorNum);
internallyPressed.sort();
}
});
});
floors.forEach(function(floor){
floor.on("up_button_pressed", function(floorNum) {
if(!upPressed.contains(floorNum)){
upPressed.push(floorNum);
upPressed.sort();
}
});
floor.on("down_button_pressed", function(floorNum) {
if(!downPressed.contains(floorNum)){
downPressed.push(floorNum);
downPressed.sort();
}
});
});
var elevator = elevators[0];
//elevator.on("floor_button_pressed", function(floorNum) {
// elevator.goToFloor(floorNum);
//});
elevator.on("floor_button_pressed", function(floorNum) {
elevator.on("idle", function(){
elevator.goToFloor(floorNum);
});
});
elevator.on("idle", function(){
elevator.goToFloor(0);
});
floors.forEach(function(floor){ // why is it function?
if(elevator.goingUpIndicator() && floor.floorNum() > elevator.currentFloor()){
floor.on("up_button_pressed", function() {
elevator.goToFloor(floor.floorNum());
});
}
if(elevator.goingDownIndicator() && floor.floorNum() < elevator.currentFloor()){
floor.on("down_button_pressed", function() {
elevator.goToFloor(floor.floorNum());
});
}
});
},
update: function(dt, elevators, floors) {
}
}