Created
December 28, 2015 10:58
-
-
Save fpereira1/cda14faa0cef65530b9f to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
floors.forEach(function(floor) { | |
floor.on('up_button_pressed', floorButtonPressed); | |
floor.on('down_button_pressed', floorButtonPressed); | |
}); | |
// Starts a list of waiting on floors | |
var waitingOn = []; | |
function floorButtonPressed() { | |
var floor = this; | |
waitingOn.push(floor.floorNum()); | |
} | |
elevators.forEach(function(elevator) { | |
elevator.on("idle", elevatorOnIdle) | |
elevator.on("floor_button_pressed", elevatorOnFloorButtonPressed); | |
elevator.on("passing_floor", elevatorOnPassingFloor); | |
}); | |
function elevatorOnPassingFloor (floorNum, direction) { | |
var elevator = this; | |
// var destDirection = elevator.destinationDirection(); | |
if(elevator.getPressedFloors().indexOf(floorNum) > 1) { | |
elevator.stop(); | |
} | |
} | |
function elevatorOnFloorButtonPressed(floorNum) { | |
console.log('button pressend to', floorNum); | |
var elevator = this; | |
elevator.goToFloor(floorNum); | |
} | |
function elevatorOnIdle() { | |
var elevator = this; | |
if(pressed.length > 0) { | |
pressed.forEach(function(floor) { | |
elevator.goToFloor(floor.floorNum()); | |
}); | |
} else if (waitingOn.length) { | |
console.log('Go on to the list of wait', waitingOn); | |
var n = waitingOn.shift(); | |
elevator.goToFloor(n); | |
} else { | |
elevator.goToFloor(0); | |
} | |
} | |
}, | |
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