Skip to content

Instantly share code, notes, and snippets.

@steinuil
Created October 19, 2022 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steinuil/21b49b96eaaac4b792a0c69a7d82a4f9 to your computer and use it in GitHub Desktop.
Save steinuil/21b49b96eaaac4b792a0c69a7d82a4f9 to your computer and use it in GitHub Desktop.
Elevator Saga

TypeScript template for https://play.elevatorsaga.com/.

Simply download all the gist files and open up in VS code and you'll get type checking.

To run a solution simply copy the whole content of the JS file and paste it into the website.

interface ElevatorEvents {
idle: () => void;
floor_button_pressed: (floorNum: number) => void;
passing_floor: (floorNum: number, direction: "up" | "down") => void;
stopped_at_floor: (floorNum: number) => void;
}
interface Elevator {
goToFloor(floorNum: number, queueFirst?: boolean): void;
stop(): void;
currentFloor(): number;
goingUpIndicator(state?: boolean): boolean;
goingDownIndicator(state?: boolean): boolean;
maxPassengerCount(): number;
loadFactor(): number;
destinationDirection(): "up" | "down" | "stopped";
destinationQueue: number[];
checkDestinationQueue(): void;
getPressedFloors(): number[];
on<E extends keyof ElevatorEvents>(type: E, handler: ElevatorEvents[E]): void;
}
interface Floor {
floorNum: number;
on(
type: "up_button_pressed" | "down_button_pressed",
handler: () => void
): void;
}
interface GameState {
init: (elevators: Elevator[], floors: Floor[]) => void;
update: (dt: number, elevators: Elevator[], floors: Floor[]) => void;
}
/// <reference path="./elevatorgame.d.ts" />
/** @type {GameState} */
({
init: function(elevators, floors) {
// Do stuff with the elevators and floors, which are both arrays of objects
},
update: function(dt, elevators, floors) {
// Do more stuff with the elevators and floors
// dt is the number of game seconds that passed since the last time update was called
}
})
{
"compilerOptions": {
"target": "es2016",
"module": "None",
"allowJs": true,
"checkJs": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment