Skip to content

Instantly share code, notes, and snippets.

@eridal
Created January 23, 2015 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eridal/7ce55190837801811067 to your computer and use it in GitHub Desktop.
Save eridal/7ce55190837801811067 to your computer and use it in GitHub Desktop.
{
init: function(elevators, floors) {
var waiting = [];
elevators.forEach(function (elevator) {
elevator.on("idle", function() {
var i = waiting.length;
while (i-- > 0) {
if (waiting[i] > 0) {
waiting[i] = 0;
this.goToFloor(i);
return;
}
}
this.stop();
});
elevator.on("floor_button_pressed", function(floorNum) {
this.goToFloor(floorNum);
});
});
floors.forEach(function(floor, floorNum) {
waiting[floorNum] = 0;
floor.on("up_button_pressed", function() {
waiting[this.floorNum()] += 1;
});
floor.on("down_button_pressed", function() {
waiting[this.floorNum()] += 1;
});
});
},
update: function(dt, elevators, floors) {
// We normally don't need to do anything here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment