aboutsummaryrefslogtreecommitdiff
path: root/src/Cell/Cell.ts
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-03-12 15:10:54 +0300
committereug-vs <eugene@eug-vs.xyz>2022-03-12 15:10:54 +0300
commit2e6a4a8761bf037283f7eb8dbfd57ab7b9e977a9 (patch)
tree22012ec08067f92d8baf9ab3039f3f7cda3e7402 /src/Cell/Cell.ts
parent8aa2213390e01996e3f9682abfd5910c698df0e2 (diff)
downloadcarcassonne-engine-ts-2e6a4a8761bf037283f7eb8dbfd57ab7b9e977a9.tar.gz
refactor: rename Cell -> Tile, Item -> Feature
Diffstat (limited to 'src/Cell/Cell.ts')
-rw-r--r--src/Cell/Cell.ts76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/Cell/Cell.ts b/src/Cell/Cell.ts
deleted file mode 100644
index 70bb792..0000000
--- a/src/Cell/Cell.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import _ from 'lodash';
-import Debug, { Debugger } from 'debug';
-
-const debug = Debug('cell');
-
-export enum Direction {
- North,
- East,
- South,
- West
-}
-
-export enum Item {
- Empty = " ",
- Road = "R",
- Town = "T",
- River = "I",
- Church = "C",
-}
-
-export interface Attachment {
- attachTo: Cell;
- side: Direction;
- cell: Cell;
- rotation: number; // Clockwise rotation of a cell
-}
-
-
-export default class Cell {
- center: Item;
- private sides: [Item, Item, Item, Item];
- neighbors: [Cell, Cell, Cell, Cell];
- 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;
- }
-
- 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) {
- debug(`Rotating ${rotation} clockwise`)
- this.orientation = this.orientation - rotation;
- }
-
- getAttachments(cell: Cell) {
- return _.flatten([0, 1, 2, 3].map(side => {
- const item = this.getSide(side);
- return [0, 1, 2, 3]
- .filter(rotation => cell.getSide(side - rotation + 2) === item)
- .map(rotation => ({
- cell,
- rotation,
- side,
- attachTo: this as Cell
- }))
- }));
- }
-
- attach(cell: Cell, side: Direction) {
- if (this.neighbors[side]) throw new Error('There is something already attached to this side!');
- this.neighbors[side] = cell;
- }
-}