Skip to content

Solutions by reaperes

Kim Namhoon edited this page Mar 3, 2015 · 1 revision

Just insert this code on init function. It will work until #5 level.

_.each(elevators, function(elevator) {
  elevator.on("floor_button_pressed", function (floorNum) {
    addToDestinationQuque(elevator, floorNum);
  });
});

_.each(floors, function (floor) {
  floor.on("up_button_pressed down_button_pressed", function () {
    addToRandomDestinationQueue(floor.level);
  });
});

function addToDestinationQuque(elevator, floor) {
  if (elevator.destinationQueue.indexOf(floor) === -1)
    elevator.destinationQueue.push(floor);
  elevator.checkDestinationQueue();
}

var rotator = 0;
function addToRandomDestinationQueue(floor) {
  var elevator = elevators[(rotator++) % elevators.length];
  if (elevator.destinationQueue.indexOf(floor) === -1)
    elevator.destinationQueue.push(floor);
  elevator.checkDestinationQueue();
}
Clone this wiki locally