Last active
August 29, 2015 14:14
-
-
Save jnewc/2ae116f8eb67405c0119 to your computer and use it in GitHub Desktop.
Elevator Saga Simple Algorithm ( < Challenge 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 findElevator = function() { | |
return _.find(elevators, function(e) { return e.loadFactor() < 0.5; }); | |
}; | |
var setupFloor = function(floor) { | |
floor.on('up_button_pressed', function(floorNum) { | |
console.log("UP: ", this.level); | |
var e = findElevator(); | |
e && e.goToFloor(this.level); | |
}); | |
floor.on('down_button_pressed', function(floorNum) { | |
console.log("DOWN: ", this.level); | |
var e = findElevator(); | |
e && e.goToFloor(this.level); | |
}); | |
}; | |
var setupElevator = function(elevator) { | |
elevator.on('floor_button_pressed', function(floorNum) { | |
elevator.goToFloor(floorNum); | |
}); | |
elevator.on('idle', function() { | |
}); | |
}; | |
floors.forEach(setupFloor); | |
elevators.forEach(setupElevator); | |
}, | |
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