diff options
Diffstat (limited to 'src/Cell/Cell.ts')
-rw-r--r-- | src/Cell/Cell.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Cell/Cell.ts b/src/Cell/Cell.ts new file mode 100644 index 0000000..23fdc9e --- /dev/null +++ b/src/Cell/Cell.ts @@ -0,0 +1,55 @@ +import Debug, { Debugger } from 'debug'; + +export enum Direction { + North, + East, + South, + West +} + +export enum Item { + Empty = " ", + Road = "R", + Town = "T", + River = "I", + Church = "C", +} + +export default class Cell { + center: Item; + private sides: [Item, Item, Item, Item]; + private orientation: number // amount of 90-degree counter-clockwise rotations from original orientation + shield?: boolean; + + debug: Debugger; + + public constructor(center: Item, sides: [Item, Item, Item, Item], orientation = 0, shield = false) { + this.center = center; + this.sides = sides; + this.shield = shield; + this.orientation = orientation; + + this.debug = Debug('cell'); + } + + toString() { + return; + } + + print() { + console.log( ` ${this.getSide(Direction.North)} \n${this.getSide(Direction.West)}${this.center}${this.getSide(Direction.East)}\n ${this.getSide(Direction.South)} `); + } + + getSide(direction: Direction) { + return this.sides[(((this.orientation + direction) % 4) + 4) % 4]; + } + + rotate(rotation = 1) { + this.debug(`Rotating ${rotation} clockwise`) + this.orientation = this.orientation - rotation; + } + + isAttachable(cell: Cell, side: Direction) { + return (this.getSide(side) === cell.getSide(side + 2)); + } +} |