Skip to content

Instantly share code, notes, and snippets.

@georgevanburgh
Created November 19, 2016 16:24
Show Gist options
  • Save georgevanburgh/177df77b8413c0f4432ace2b9edcd7ba to your computer and use it in GitHub Desktop.
Save georgevanburgh/177df77b8413c0f4432ace2b9edcd7ba to your computer and use it in GitHub Desktop.
Elevator Saga Levels 1-6
{
init: function(elevators, floors) {
var numberOfElevators = elevators.length;
for (var i = 0; i < numberOfElevators; i++) {
elevators[i].destinationQueue = [];
elevators[i].on("floor_button_pressed", function(floorNum) {
console.log("floor_button_pressed - adding: " + floorNum);
this.destinationQueue + floorNum;
})
// Whenever the elevator is idle (has no more queued destinations) ...
elevators[i].on("idle", function() {
if (this.getPressedFloors().length == 0) {
this.goToFloor(0);
} else {
this.goToFloor(this.getPressedFloors()[0]);
}
});
}
},
update: function(dt, elevators, floors) {
console.log("Going to " + elevators[0].destinationQueue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment