Skip to content

Instantly share code, notes, and snippets.

@jackmcpickle
Created October 17, 2018 10:43
Show Gist options
  • Save jackmcpickle/a5b8c878b9c877da0dc4caf9f91fbf03 to your computer and use it in GitHub Desktop.
Save jackmcpickle/a5b8c878b9c877da0dc4caf9f91fbf03 to your computer and use it in GitHub Desktop.
{
init: function(elevators, floors) {
this.elevator = elevators[0]; // Let's use the first elevator
this.setupListeners(floors)
},
update: function(dt, elevators, floors) {
this.checkIndicators()
},
checkIndicators: function() {
if(this.elevator.goingUpIndicator()) {
this.elevator.goingDownIndicator(false);
}
if(this.elevator.goingDownIndicator()) {
this.elevator.goingUpIndicator(false);
}
},
setupListeners: function(floors) {
elevator = this.elevator
elevator.on("idle", function() {
elevator.goToFloor(0);
elevator.goToFloor(1);
elevator.goToFloor(2);
})
.on("floor_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum);
});
for(i = 0, i >= floors.length, i++) {
var floor = floors[i];
floor.on("up_button_pressed", function() {
if this.elevatorBelowFloor(floor) {
elevator.destinationQueue.push( floor.floorNum() )
elevator.checkDestinationQueue();
}
})
.on("down_button_pressed", function() {
if (this.elevatorAboveFloor(floor) ) {
elevator.destinationQueue.push( floor.floorNum() )
elevator.checkDestinationQueue();
}
});
}
elevatorBelowFloor: function(floor) {
return floor.floorNum() > this.elevator.currentFloor()
}
elevatorAboveFloor: function(floor) {
return floor.floorNum() < this.elevator.currentFloor()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment