30 lines
750 B
TypeScript
30 lines
750 B
TypeScript
import { Direction } from "../constants/Direction";
|
|
import { Border } from "./Border";
|
|
import { Cell } from "./Cell";
|
|
import { Exit } from "./Exit";
|
|
|
|
export class ExternalNode {
|
|
public readonly direction: Direction;
|
|
private border?: Border;
|
|
public readonly cell: Cell;
|
|
|
|
constructor(cell: Cell, direction: Direction) {
|
|
this.cell = cell;
|
|
this.direction = direction;
|
|
}
|
|
|
|
public linkToNode(other: ExternalNode | Exit) {
|
|
this.border = new Border(this, other);
|
|
if (other instanceof ExternalNode) {
|
|
other.border = this.border;
|
|
}
|
|
}
|
|
|
|
public traverseBorder(): ExternalNode | Exit {
|
|
if (!this.border) {
|
|
throw Error(`Missing border for node`);
|
|
}
|
|
return (this.border as Border).traverseFrom(this);
|
|
}
|
|
}
|