UNPKG

@ludw1gj/maze-generation

Version:

Maze generation algorithms.

74 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Cell { constructor(position, isVisited, walls) { this._position = position; this._isVisited = isVisited !== undefined ? isVisited : false; this._walls = walls ? walls : { north: true, east: true, south: true, west: true, }; } createCopy() { return new Cell(this._position, this._isVisited, this._walls); } get position() { return this._position; } get isVisited() { return this._isVisited; } get walls() { return this._walls; } setVisited() { this._isVisited = true; } destroyWall(direction) { switch (direction) { case "NORTH": { this._walls.north = false; break; } case "EAST": { this._walls.east = false; break; } case "SOUTH": { this._walls.south = false; break; } case "WEST": { this._walls.west = false; break; } default: throw new Error("invalid direction given"); } } getChangeInPosition(dir) { const { x, y } = this._position; switch (dir) { case "NORTH": { return { x, y: y - 1 }; } case "EAST": { return { x: x + 1, y }; } case "SOUTH": { return { x, y: y + 1 }; } case "WEST": { return { x: x - 1, y }; } default: throw new Error("invalid direction given"); } } } exports.Cell = Cell; //# sourceMappingURL=cell.js.map