Skip to content

Instantly share code, notes, and snippets.

@deadPix3l
Created June 7, 2017 17:56
Show Gist options
  • Save deadPix3l/321f9c89b0120ad901d3cdf153676937 to your computer and use it in GitHub Desktop.
Save deadPix3l/321f9c89b0120ad901d3cdf153676937 to your computer and use it in GitHub Desktop.
Elevator saga
{
init: function(elevators, floors) {
elevators.forEach(function(x, index){
x.on("floor_button_pressed", function(floorNum) {
if (x.currentFloor() > floorNum) {
x.goingDownIndicator(true);
x.goingUpIndicator(false);
}
else {
x.goingDownIndicator(false);
x.goingUpIndicator(true);
}
x.goToFloor(floorNum);
});
x.on("idle", function() {
x.goingDownIndicator(true);
x.goingUpIndicator(true);
});
});
floors.forEach(function(y, index){
y.on("up_button_pressed", function() {
elevators[0].goingDownIndicator(false);
elevators[0].goingUpIndicator(true);
elevators[0].goToFloor(index);
});
y.on("down_button_pressed", function() {
elevators[0].goingDownIndicator(true);
elevators[0].goingUpIndicator(false);
elevators[0].goToFloor(index);
});
});
},
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