Created
January 24, 2015 09:03
-
-
Save ergusto/730df778fe11ca955232 to your computer and use it in GitHub Desktop.
Solution for http://play.elevatorsaga.com/ levels 1-6
This file contains 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) { | |
var waitingFloors = []; | |
_.each(elevators, function(elevator) { | |
elevator.on("floor_button_pressed", function(floorNum) { | |
elevator.goToFloor(floorNum); | |
}); | |
elevator.on("up_button_pressed", function(floorNum) { | |
elevator.goToFloor(floorNum); | |
}); | |
elevator.on("idle", function() { | |
var waiting = waitingFloors[0]; | |
if (waiting) { | |
elevator.goToFloor(waiting.level); | |
} else { | |
elevator.goToFloor(0); | |
} | |
}); | |
elevator.on("stopped_at_floor", function(floorNum) { | |
var floor = floors[floorNum]; | |
var index = waitingFloors.indexOf(floor); | |
if (index) { | |
waitingFloors.splice(index, 1); | |
} | |
}); | |
}); | |
_.each(floors, function(floor) { | |
floor.on("up_button_pressed down_button_pressed", function() { | |
waitingFloors.push(floor); | |
}); | |
}); | |
}, | |
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