Created
January 23, 2015 04:50
-
-
Save eridal/7ce55190837801811067 to your computer and use it in GitHub Desktop.
Elevator Saga: http://play.elevatorsaga.com
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 waiting = []; | |
elevators.forEach(function (elevator) { | |
elevator.on("idle", function() { | |
var i = waiting.length; | |
while (i-- > 0) { | |
if (waiting[i] > 0) { | |
waiting[i] = 0; | |
this.goToFloor(i); | |
return; | |
} | |
} | |
this.stop(); | |
}); | |
elevator.on("floor_button_pressed", function(floorNum) { | |
this.goToFloor(floorNum); | |
}); | |
}); | |
floors.forEach(function(floor, floorNum) { | |
waiting[floorNum] = 0; | |
floor.on("up_button_pressed", function() { | |
waiting[this.floorNum()] += 1; | |
}); | |
floor.on("down_button_pressed", function() { | |
waiting[this.floorNum()] += 1; | |
}); | |
}); | |
}, | |
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