Created
January 27, 2015 22:05
-
-
Save davidblurton/be123aa635ce3f78dbe0 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", function() { | |
var emptiestElevator = getEmptiestElevator(); | |
emptiestElevator.goToFloor(floor.floorNum()); | |
}); | |
floor.on("down_button_pressed", function() { | |
var emptiestElevator = getEmptiestElevator(); | |
emptiestElevator.goToFloor(floor.floorNum()); | |
}); | |
}); | |
elevators.forEach(function(elevator) { | |
elevator.on("floor_button_pressed", function(floorNum) { | |
elevator.goToFloor(floorNum); | |
}); | |
}); | |
function getEmptiestElevator() { | |
elevators.sort(function(a, b) { | |
return a.loadFactor() - b.loadFactor(); | |
}); | |
return elevators[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