Skip to content

Instantly share code, notes, and snippets.

@garyjoy
Last active October 24, 2019 16:25
Show Gist options
  • Save garyjoy/8d8d83264bbd398d6ec38a10a293fc27 to your computer and use it in GitHub Desktop.
Save garyjoy/8d8d83264bbd398d6ec38a10a293fc27 to your computer and use it in GitHub Desktop.
Elevator Saga 01 - Starter for Ten...
{
init: function(elevators, floors) {
function getElevator() {
// Return a random elevator...
return elevators[Math.floor(Math.random() * elevators.length)];
}
floors.forEach(floor => {
floor.on("up_button_pressed", function() {
getElevator().goToFloor(floor.floorNum())
})
floor.on("down_button_pressed", function() {
getElevator().goToFloor(floor.floorNum())
})
})
elevators.forEach(elevator => {
elevator.on("floor_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum)
})
})
},
update: function(dt, elevators, floors) {
}
}
@garyjoy
Copy link
Author

garyjoy commented Oct 23, 2019

This should be used as a starting point for your solution. It will pass the first few challenges (not always on the first attempt).

You might consider...

  • improving the logic to determine which Elevator responds to Floor events
  • preventing Elevators from passing Floors in the destination queue without stopping
  • setting the direction indicators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment