Skip to content

Instantly share code, notes, and snippets.

@steveruizok
Last active March 14, 2022 23:50
Show Gist options
  • Save steveruizok/1bc4b64f0288495b48c1e5dd147c61cd to your computer and use it in GitHub Desktop.
Save steveruizok/1bc4b64f0288495b48c1e5dd147c61cd to your computer and use it in GitHub Desktop.
TypeScript declarations for Warrior.js. (mostly complete)
declare type Direction = "forward" | "left" | "right" | "backward" | string
declare type AbsoluteDirection = "north" | "east" | "west" | "south" | string
declare interface Unit {
isEnemy(): boolean
isAlive(): boolean
isBound(): boolean
isUnderEffect(): boolean
}
declare type Character = string
declare interface Space {
getCharacter(): Character | undefined
isEmpty(): boolean
isStairs(): boolean
isWall(): boolean
isUnit(): boolean
getUnit(): Unit | undefined
as(unit: Unit): {
getLocation(): number[]
getUnit(): Unit | undefined
isEmpty(): boolean
isStairs(): boolean
isUnit(): boolean
isWall(): boolean
}
toString(): "wall" | "nothing" | string
toJSON(): {
character: string | undefined
unit: string | undefined
}
}
declare interface Warrior {
attack(direction?: Direction): void
bind(direction?: Direction): void
detonate(direction?: Direction): void
directionOf(space: Space): Direction
directionOfStairs(): Direction
distanceOf(space: Space): number
feel(direction?: Direction): Space
health(): number
listen(): Space[]
look(direction?: Direction): Space[]
maxHealth(): number
pivot(direction?: Direction): void
rescue(direction?: Direction): void
rest(): void
shoot(direction?: Direction): void
think(...args: any[]): void
walk(direction?: Direction): void
}
class Player {
/**
* @param {Warrior} warrior
*/
playTurn(warrior) {
warrior.walk()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment