Created
June 7, 2017 17:56
-
-
Save deadPix3l/321f9c89b0120ad901d3cdf153676937 to your computer and use it in GitHub Desktop.
Elevator saga
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
{ | |
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