UNPKG

battleships-engine

Version:
71 lines (66 loc) 1.83 kB
type ShipType = "aircraft_carrier" | "battleship" | "destroyer" | "submarine" | "cruiser"; type Direction = "hor" | "vert"; type TCoords = { x: number; y: number; }; declare class Coords { x: number; y: number; constructor(coords?: TCoords); toString(): string; [Symbol.iterator](): Generator<{ type: "x" | "y"; number: number; }, void, unknown>; } declare class Ship { readonly length: number; type: ShipType; beenHitTimes: number; coords: Coords; direction: Direction; constructor({ coords, type, direction, }: { coords: TCoords; direction: Direction; type: ShipType; }); hit(): void; isSunk(): boolean; [Symbol.iterator](): Generator<{ x: number; y: number; toString: () => string; }, void, unknown>; } declare class GameBoard { ships: Map<ShipType, Ship>; takenCells: Map<string, ShipType>; missed: Map<string, boolean>; hitCells: Map<string, boolean>; constructor(ships?: Ship[]); private fillTakenCellsWithShip; inspectCoordsInShips({ coords: paramCoords, missCb, matchCb, }: { coords: TCoords; matchCb: (ship: Ship) => void; missCb: () => void; }): void; placeShip(params: { type: ShipType; coords: TCoords; direction: Direction; }): void; removeShip(ship: Ship): void; moveShip(startingShip: Ship, newShipInfo: { coords: TCoords; direction: Direction; }): void; receiveAttack(coords: TCoords): void; hasLost(): boolean; randomlyPlaceShip({ type, direction, }: { type: ShipType; direction?: Direction; }): void; randomlyPlaceShips(): void; } export { Coords, type Direction, GameBoard, Ship, type ShipType, type TCoords };