Skip to content

Instantly share code, notes, and snippets.

@netpro2k
Forked from loisaidasam/elevator_saga.js
Last active August 29, 2015 14:13
Show Gist options
  • Save netpro2k/583bb49ee51cf23eafe4 to your computer and use it in GitHub Desktop.
Save netpro2k/583bb49ee51cf23eafe4 to your computer and use it in GitHub Desktop.
{
// Docs: http://play.elevatorsaga.com/documentation.html#docs
init: function(elevators, floors) {
console.log("init() with " + elevators.length + " elevators and " + floors.length + " floors");
for (var i=0; i<elevators.length; i++) {
(function(elevator){
elevator.on("idle", function() {
console.log("idle");
elevator.goToFloor(0);
//console.log("done idling");
});
elevator.on("floor_button_pressed", function(floorNum) {
console.log("floor_button_pressed " + floorNum);
elevator.goToFloor(floorNum, true);
console.log("elevator.destinationQueue: " + elevator.destinationQueue);
});
})(elevators[i])
}
var defaultElevator = elevators[0];
for (var i=0; i<floors.length; i++) {
(function(floor){
var floorNum = floor.floorNum();
floor.on("up_button_pressed", function() {
console.log("up_button_pressed from floor " + floorNum);
defaultElevator.goToFloor(floorNum);
console.log("defaultElevator.destinationQueue: " + defaultElevator.destinationQueue);
});
floor.on("down_button_pressed", function() {
console.log("down_button_pressed from floor " + floorNum);
defaultElevator.goToFloor(floorNum);
console.log("defaultElevator.destinationQueue: " + defaultElevator.destinationQueue);
});
})(floors[i])
}
},
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