Last active
August 29, 2015 14:14
-
-
Save gsharp/d515164acf0c574a4022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍