-
-
Save netpro2k/583bb49ee51cf23eafe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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