aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/ts/ghost.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/ts/ghost.ts')
-rw-r--r--frontend/ts/ghost.ts25
1 files changed, 21 insertions, 4 deletions
diff --git a/frontend/ts/ghost.ts b/frontend/ts/ghost.ts
index 208127d..9a6008a 100644
--- a/frontend/ts/ghost.ts
+++ b/frontend/ts/ghost.ts
@@ -1,25 +1,36 @@
-import { Chequer, GameBoard, HoBSquare, HomesOrBases, Square, tColors } from "../../helpers/helpersBack";
+import { Chequer, GameBoard, HoBSquare, HomesOrBases, OldTd, Square, tColors } from "../../helpers/helpersBack";
import gameBoardClass from "./gameBoard.js";
import gameTable from "./gameTable.js";
+import StartGame from "./startGame.js";
export default class ghost {
static ghostsTds: Array<{ td: HTMLElement, class: string }> = [];
static interval: any;
static hide = true;
+ static oldTd: OldTd;
+
static showGhost(chequer: Chequer | HoBSquare, color: tColors) {
if (chequer.ghost === undefined || chequer.ghost.coords === undefined) {
chequer.ghost?.coords === undefined ? console.log("showShost::chequer.ghost.coords === undefined", chequer.ghost?.coords === undefined) : '';
return;
}
- gameBoardClass.showChequer(chequer.ghost.coords, 4)
+ let td = gameTable.getTd(chequer.ghost.coords);
+ if (td.dataset.count === undefined) {
+ throw new Error("td.dataset.count === undefined");
+ }
+ ghost.oldTd = { className: td.className, innerHTML: td.innerHTML, count: td.dataset.count };
+ gameBoardClass.showChequer(chequer.ghost.coords, 4, StartGame.colors[color])
}
+
static hideGhost(chequer: Chequer | HoBSquare): void {
if (chequer.ghost === undefined || chequer.ghost.coords === undefined) {
chequer.ghost?.coords === undefined ? console.log("hideGhost::chequer.ghost.coords === undefined", chequer.ghost?.coords === undefined) : '';
return;
}
- gameBoardClass.hideChequer(chequer.ghost.coords);
+ gameBoardClass.hideChequer(chequer.ghost.coords, false, ghost.oldTd);
+ ghost.oldTd = { className: '', innerHTML: '', count: '' };
}
+
static removeGhosts(gameBoard: GameBoard, color: tColors): void {
for (let square of gameBoard.map) {
for (let chequer of square.chequers) {
@@ -33,6 +44,7 @@ export default class ghost {
chequer.ghost = undefined;
}
}
+
static anyGhosts(gameBoard: GameBoard, color: tColors): boolean {
for (let square of gameBoard.map) {
for (let chequer of square.chequers) {
@@ -50,6 +62,7 @@ export default class ghost {
}
return false;
}
+
static allBlink(gameBoard: GameBoard, color: tColors) {
for (let square of gameBoard.map) {
if (square.chequers.some(el => el.ghost !== undefined) === true)
@@ -64,18 +77,22 @@ export default class ghost {
ghost.blink(chequer);
}
}
+
static blink(chequer: Square | HoBSquare) {
if (ghost.interval === undefined)
ghost.interval = setInterval(ghost.blinking, 700);
let td = gameTable.getTd({ x: chequer.x, y: chequer.y });
ghost.ghostsTds.push({ td, class: td.className });
}
+
static blinking() {
for (let td of ghost.ghostsTds) {
- td.td.className = ghost.hide === true ? '' : td.class;
+ if (!td.td.className.includes("white"))
+ td.td.className = ghost.hide === true ? 'chequer chequer-pink' : td.class;
}
ghost.hide = !ghost.hide;
}
+
static allStopBlink() {
clearInterval(ghost.interval);
ghost.interval = undefined;