SHARE
TWEET

Untitled

a guest Mar 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     init: function(elevators, floors) {
  3.         //var elevator = elevators[0]; // Let's use the first elevator
  4.         //var i = 0;
  5.    
  6.         elevators.forEach(function(elevator, i) {
  7.             // Whenever the elevator is idle (has no more queued destinations) ...
  8.             elevator.on("idle", function() {
  9.                 console.log("Elevator" + i + " is idle");
  10.                 if (elevator.destinationQueue.length === 0) {
  11.                     elevator.goToFloor(0);
  12.                 }
  13.             });
  14.  
  15.             elevator.on("floor_button_pressed", function(floorNum) {
  16.                 //console.log("Elevator" + i + ": " + elevator.loadFactor() + ". Floor " + floorNum);
  17.                 elevator.destinationQueue.push(floorNum);
  18.                 elevator.checkDestinationQueue();
  19.                 if (elevator.loadFactor() < 0.5) {
  20.                     return;
  21.                 }
  22.                
  23.                 elevator.goToFloor(elevator.destinationQueue[0]);
  24.             });
  25.        
  26.             elevator.on("stopped_at_floor", function(floorNum) {
  27.                 elevator.destinationQueue = elevator.destinationQueue.filter(function(destination) {
  28.                     return destination !== floorNum;
  29.                 });
  30.                
  31.                 elevator.checkDestinationQueue();
  32.             });
  33.         });
  34.        
  35.     },
  36.     update: function(dt, elevators, floors) {
  37.         // We normally don't need to do anything here
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top