Created
February 18, 2015 03:05
-
-
Save bento-n-box/9b5246d533fbd0a5145c to your computer and use it in GitHub Desktop.
basic elevator game code 1-6
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) { | |
// Create Queue System for People waiting | |
var floorQueue = []; | |
// Loop Through each elevator | |
// Bind Events to elevator | |
elevators.forEach(function(elevator) { | |
// When Elevators is idle | |
elevator.on("idle", function() { | |
// If people waiting on floor, go to them | |
if (floorQueue.length > 0) { | |
elevator.goToFloor(floorQueue[0]); | |
floorQueue.shift(); | |
} else { // else go to floor | |
elevator.goToFloor(0); | |
} | |
}); | |
// FLoor Pressed, go directly to floor | |
elevator.on("floor_button_pressed", function(floorNum) { | |
elevator.goToFloor(floorNum); | |
}); | |
}); | |
floors.forEach(function(floor) { | |
floor.on("up_button_pressed", function() { | |
var floorNum = floor.floorNum(); | |
floorQueue.push(floorNum); | |
}); | |
floor.on("down_button_pressed", function() { | |
var floorNum = floor.floorNum(); | |
floorQueue.push(floorNum); | |
}); | |
}); | |
}, | |
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