Skip to content

Instantly share code, notes, and snippets.

@gsharp
Last active August 29, 2015 14:14
Show Gist options
  • Save gsharp/d515164acf0c574a4022 to your computer and use it in GitHub Desktop.
Save gsharp/d515164acf0c574a4022 to your computer and use it in GitHub Desktop.
{
init: function(elevators, floors) {
var elevator = elevators[0]; // Let's use the first elevator
function go(num) {
// set a listener for up button pressed
floors[num].on("up_button_pressed", function() {
console.log ("floor button up pressed, going to floor: " + num);
elevator.goToFloor(num);
})
// set a listener for up down button pressed
floors[num].on("down_button_pressed", function() {
console.log ("floor button down pressed, going to floor: " + num);
elevator.goToFloor(num);
})
}
// for each floor set the floor button listener in a closure
for (i=0;i < floors.length; i++){
go(i);
}
// when people are in the elevator prioritize where they want to go first
elevator.on("floor_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum,true);
});
},
update: function(dt, elevators, floors) {
// We normally don't need to do anything here
}
}
@SeanPlusPlus
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment