{ init: function(elevators, floors) { this.elevator = elevators[0]; // Let's use the first elevator this.setupListeners(floors) }, update: function(dt, elevators, floors) { this.checkIndicators() }, checkIndicators: function() { if(this.elevator.goingUpIndicator()) { this.elevator.goingDownIndicator(false); } if(this.elevator.goingDownIndicator()) { this.elevator.goingUpIndicator(false); } }, setupListeners: function(floors) { elevator = this.elevator elevator.on("idle", function() { elevator.goToFloor(0); elevator.goToFloor(1); elevator.goToFloor(2); }) .on("floor_button_pressed", function(floorNum) { elevator.goToFloor(floorNum); }); for(i = 0, i >= floors.length, i++) { var floor = floors[i]; floor.on("up_button_pressed", function() { if this.elevatorBelowFloor(floor) { elevator.destinationQueue.push( floor.floorNum() ) elevator.checkDestinationQueue(); } }) .on("down_button_pressed", function() { if (this.elevatorAboveFloor(floor) ) { elevator.destinationQueue.push( floor.floorNum() ) elevator.checkDestinationQueue(); } }); } elevatorBelowFloor: function(floor) { return floor.floorNum() > this.elevator.currentFloor() } elevatorAboveFloor: function(floor) { return floor.floorNum() < this.elevator.currentFloor() } } }