Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- init: function(elevators, floors) {
- //var elevator = elevators[0]; // Let's use the first elevator
- //var i = 0;
- elevators.forEach(function(elevator, i) {
- // Whenever the elevator is idle (has no more queued destinations) ...
- elevator.on("idle", function() {
- console.log("Elevator" + i + " is idle");
- if (elevator.destinationQueue.length === 0) {
- elevator.goToFloor(0);
- }
- });
- elevator.on("floor_button_pressed", function(floorNum) {
- //console.log("Elevator" + i + ": " + elevator.loadFactor() + ". Floor " + floorNum);
- elevator.destinationQueue.push(floorNum);
- elevator.checkDestinationQueue();
- if (elevator.loadFactor() < 0.5) {
- return;
- }
- elevator.goToFloor(elevator.destinationQueue[0]);
- });
- elevator.on("stopped_at_floor", function(floorNum) {
- elevator.destinationQueue = elevator.destinationQueue.filter(function(destination) {
- return destination !== floorNum;
- });
- elevator.checkDestinationQueue();
- });
- });
- },
- update: function(dt, elevators, floors) {
- // We normally don't need to do anything here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement