aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/ts/ghost.ts
diff options
context:
space:
mode:
authorMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-25 12:07:36 +0200
committerMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-25 12:07:36 +0200
commit013319d7a4651d1708280f556e39c2f03839426a (patch)
tree704e51c6d4d96360611819628be3c78edec2f9d8 /frontend/ts/ghost.ts
parent13dcc2c8fc1d11e3b94432fffc4c4f186bd94d29 (diff)
downloadfia-013319d7a4651d1708280f556e39c2f03839426a.tar.gz
fia-013319d7a4651d1708280f556e39c2f03839426a.tar.zst
fia-013319d7a4651d1708280f556e39c2f03839426a.zip
Almost going in a circle
Diffstat (limited to 'frontend/ts/ghost.ts')
-rw-r--r--frontend/ts/ghost.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/frontend/ts/ghost.ts b/frontend/ts/ghost.ts
new file mode 100644
index 0000000..e7b4cb0
--- /dev/null
+++ b/frontend/ts/ghost.ts
@@ -0,0 +1,87 @@
+import { Chequer, GameBoard, HoBSquare, HomesOrBases, Square, tColors } from "../../helpers/helpersBack";
+import gameBoardClass from "./gameBoard.js";
+import gameTable from "./gameTable.js";
+
+export default class ghost {
+ static ghostsTds: Array<{ td: HTMLElement, class: string }> = [];
+ static interval: any;
+ static hide = true;
+ 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, 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);
+ }
+ static removeGhosts(gameBoard: GameBoard, color: tColors): void {
+ for (let square of gameBoard.map) {
+ for (let chequer of square.chequers) {
+ chequer.ghost = undefined;
+ }
+ }
+ for (let chequer of gameBoard.bases[color as keyof HomesOrBases]) {
+ chequer.ghost = undefined;
+ }
+ for (let chequer of gameBoard.homes[color as keyof HomesOrBases]) {
+ chequer.ghost = undefined;
+ }
+ }
+ static anyGhosts(gameBoard: GameBoard, color: tColors): boolean {
+ for (let square of gameBoard.map) {
+ for (let chequer of square.chequers) {
+ if (chequer.ghost !== undefined)
+ return true;
+ }
+ }
+ for (let chequer of gameBoard.bases[color as keyof HomesOrBases]) {
+ if (chequer.ghost !== undefined)
+ return true;
+ }
+ for (let chequer of gameBoard.homes[color as keyof HomesOrBases]) {
+ if (chequer.ghost !== undefined)
+ return true;
+ }
+ return false;
+ }
+ static allBlink(gameBoard: GameBoard, color: tColors) {
+ for (let square of gameBoard.map) {
+ if (square.chequers.some(el => el.ghost !== undefined))
+ ghost.blink(square);
+ }
+ for (let chequer of gameBoard.bases[color as keyof HomesOrBases]) {
+ if (chequer.ghost !== undefined)
+ ghost.blink(chequer);
+ }
+ for (let chequer of gameBoard.homes[color as keyof HomesOrBases]) {
+ if (chequer.ghost !== undefined)
+ ghost.blink(chequer);
+ }
+ }
+ static blink(chequer: Square | HoBSquare) {
+ if (ghost.interval === undefined)
+ ghost.interval = setInterval(ghost.blinking, 1000);
+ 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;
+ }
+ ghost.hide = !ghost.hide;
+ }
+ static allStopBlink() {
+ clearInterval(ghost.interval);
+ ghost.hide = true;
+ for (let td of ghost.ghostsTds) {
+ td.td.className = td.class;
+ }
+ ghost.ghostsTds = [];
+ }
+} \ No newline at end of file