25 lines
846 B
TypeScript
25 lines
846 B
TypeScript
import { CellType } from "../constants/CellType";
|
|
import { Direction } from "../constants/Direction";
|
|
import { ExternalNode } from "./ExternalNode";
|
|
|
|
export class Cell {
|
|
public readonly externalNodes: Map<Direction, ExternalNode>;
|
|
public readonly cellType: CellType;
|
|
|
|
constructor(cellType: CellType) {
|
|
this.externalNodes = new Map([
|
|
[Direction.NORTH, new ExternalNode(this, Direction.NORTH)],
|
|
[Direction.SOUTH, new ExternalNode(this, Direction.SOUTH)],
|
|
[Direction.EAST, new ExternalNode(this, Direction.EAST)],
|
|
[Direction.WEST, new ExternalNode(this, Direction.WEST)],
|
|
]);
|
|
this.cellType = cellType;
|
|
}
|
|
|
|
public getNodeAt(direction: Direction): ExternalNode {
|
|
const node = this.externalNodes.get(direction);
|
|
if (!node) throw Error(`Could not find node at ${direction}`);
|
|
return node!;
|
|
}
|
|
}
|