From 040d5372c1033bb7c0580ad2c9b6b32f974a20c8 Mon Sep 17 00:00:00 2001 From: Maks Jopek Date: Thu, 29 Apr 2021 20:05:06 +0200 Subject: Version 1.0 --- frontend/ts/ghost.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'frontend/ts/ghost.ts') 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; -- cgit v1.3.1