Last active
August 29, 2015 14:22
-
-
Save kutyel/37af5e7dedeb241f45ef to your computer and use it in GitHub Desktop.
This is my awesome algorythm for the Elevator Saga browser game!
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 reqFloor = 0, dir = ""; | |
floors.forEach(function(floor){ | |
floor.on("up_button_pressed", function(){ | |
dir = "up"; | |
reqFloor = floor.floorNum(); | |
}); | |
floor.on("down_button_pressed", function(){ | |
dir = "down"; | |
reqFloor = floor.floorNum(); | |
}); | |
}); | |
elevators.forEach(function(elevator){ | |
elevator.on("passing_floor", function(floor, direction){ | |
if (direction === dir && floor === reqFloor && elevator.loadFactor() < 0.75){ | |
elevator.goToFloor(reqFloor, true); | |
} | |
}) | |
elevator.on("floor_button_pressed", function(numFloor){ | |
elevator.goToFloor(numFloor); | |
}); | |
elevator.on("idle", function(){ | |
elevator.goToFloor(reqFloor); | |
}); | |
}); | |
}, | |
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