Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Created January 28, 2015 10:11
Show Gist options
  • Select an option

  • Save BinaryKitten/58edbb7c84ab57f8a980 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/58edbb7c84ab57f8a980 to your computer and use it in GitHub Desktop.
{
init: function(elevators, floors) {
for (var idx in elevators) {
elevators[idx].on('floor_button_pressed', function(floornum) {
if (this.destinationQueue.indexOf(floornum) === -1) {
this.destinationQueue.push(floornum);
this.destinationQueue.sort();
this.checkDestinationQueue();
}
});
elevators[idx].on('idle', function() {
var floorNum, floor, elevator = this;
for(floorNum in floors) {
floor = floors[floorNum];
if ((floor.buttonStates.down + floor.buttonStates.up) != "") {
for (elevatorIdx in elevators) {
if (elevators[elevatorIdx].destinationQueue.indexOf(floorNum) !== -1) {
return;
}
}
this.destinationQueue.push(floorNum);
this.checkDestinationQueue();
return;
}
}
});
elevators[idx].on('passing_floor', function(floorNum, direction) {
if (floors[floorNum].buttonStates[direction] == 'activated') {
this.destinationQueue.unshift(floorNum);
this.checkDestinationQueue();
}
if (direction == 'up' && floorNum < floors.length -1 ) {
this.goingUpIndicator(true);
this.goingDownIndicator(false);
} else {
this.goingUpIndicator(false);
this.goingDownIndicator(true);
}
});
elevators[idx].on('stopped_at_floor', function(floorNum) {
if (floorNum == 0) {
this.goingUpIndicator(true);
this.goingDownIndicator(false);
} else if (floorNum == floors.length -1) {
this.goingUpIndicator(false);
this.goingDownIndicator(true);
}
});
//elevators[idx].goToFloor(0);
elevators[idx].goingUpIndicator(true);
elevators[idx].goingDownIndicator(false);
elevators[idx].stop();
}
},
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