This is a game of programming!
Your task is to program the movement of elevators, by writing a program in
JavaScript.
The goal is to transport people in an efficient manner.
Depending on how well you do it, you can progress through the ever more difficult challenges.
Only the very best programs will be able to complete all the challenges.
Enter your code in the input window below the game view, and press the
Apply button to start the challenge.
You can increase or decrease the speed of time by pressing the
and buttons.
If your program contains an error, you can use the developer tools in your web browser to try and
debug it. If you want to start over with the code, press the
Reset button. This will revert the code to a working but
simplistic implementation.
If you have a favorite text editor, such as Sublime Text,
feel free to edit the code there and paste it into the game editor.
Your code is automatically saved in your local storage, so don't worry - it doesn't disappear if you
accidentally close the browser.
Your code must export two functions called init and update. Like this:
export function init(elevators, floors) {
// Do stuff with the elevators and floors, which are both arrays of objects
}
export function update(deltaTime, elevators, floors) {
// Do more stuff with the elevators and floors
// deltaTime is the number of game seconds that passed since the last time update was called
}
These functions will then be called by the game during the challenge.
init will be called when the challenge starts, and
update repeatedly during the challenge.
Normally you will put most of your code in the init function, to set up event listeners and logic.
elevator.goToFloor(1);
if (elevator.currentFloor() > 2) {
// Do something
}
It is possible to listen for events, like when stopping at a floor, or a button has been pressed.
elevator.on("idle", (event) => {
elevator.goToFloor(0);
});
elevator.on("call", (event, floorNum) => {
// Someone pushed a floor button in the elevator
});
floor.on("call", (event, direction) => {
if (direction === 'up') {
// Someone pressed the up button
} else {
// Someone pressed the down button
}
});
Property | Type | Explanation | Example |
---|---|---|---|
goToFloor | function | Queue the elevator to go to specified floor number. If you specify true as second argument, the elevator will go to that floor directly, and then go to any other queued floors. |
|
stop | function | Clear the destination queue and stop the elevator if it is moving. Note that you normally don't need to stop elevators - it is intended for advanced solutions with in-transit rescheduling logic. Also, note that the elevator will probably not stop at a floor, so passengers will not get out. |
|
currentFloor | function | Gets the floor number that the elevator currently is on. |
|
goingUpIndicator | function | Gets or sets the going up indicator, which will affect passenger behaviour when stopping at floors. |
|
goingDownIndicator | function | Gets or sets the going down indicator, which will affect passenger behaviour when stopping at floors. |
|
maxPassengerCount | function | Gets the maximum number of passengers that can occupy the elevator at the same time. |
|
loadFactor | function | Gets the load factor of the elevator. 0 means empty, 1 means full. Varies with passenger weights, which vary - not an exact measure. |
|
destinationDirection | function | Gets the direction the elevator is currently going to move toward. Can be "up", "down" or "stopped". | |
destinationQueue | array | The current destination queue, meaning the floor numbers the elevator is scheduled to go to. Can be modified and emptied if desired. Note that you need to call checkDestinationQueue() for the change to take effect immediately. |
|
checkDestinationQueue | function | Checks the destination queue for any new destinations to go to. Note that you only need to call this if you modify the destination queue explicitly. |
|
calls | array | Read-only. Gets the currently pressed floor numbers as an array. |
|
function | Deprecated. Use calls instead. Gets the currently pressed floor numbers as an array. |
|
Event | Explanation | Example |
---|---|---|
idle | Triggered when the elevator has completed all its tasks and is not doing anything. |
|
call | Triggered when a passenger has pressed a button inside the elevator. |
|
willPassFloor | Triggered slightly before the elevator will pass a floor. A good time to decide whether to stop at that floor. Note that this event is not triggered for the destination floor. Direction is either "up" or "down". |
|
arrive | Triggered when the elevator has arrived at a floor. |
|
Deprecated. Use call instead. Triggered when a passenger has pressed a button inside the elevator. |
|
|
Deprecated. Use willPassFloor instead. Triggered slightly before the elevator will pass a floor. A good time to decide whether to stop at that floor. Note that this event is not triggered for the destination floor. Direction is either "up" or "down". |
|
|
Deprecated. Use arrive instead. Triggered when the elevator has arrived at a floor. |
|
Property | Type | Explanation | Example |
---|---|---|---|
number | number | Gets the floor number of the floor object. Read-only. |
|
function | Deprecated. Use number instead. Gets the floor number of the floor object. |
|
Event | Explanation | Example |
---|---|---|
call | Triggered when someone has pressed the up button at a floor. Note that passengers will press the button again if they fail to enter an elevator. Direction is either "up" or "down". |
|
Deprecated. Use call instead. Triggered when someone has pressed the up button at a floor. Note that passengers will press the button again if they fail to enter an elevator. |
|
|
Deprecated. Use call instead. Triggered when someone has pressed the down button at a floor. Note that passengers will press the button again if they fail to enter an elevator. |
|