diff options
| author | Maks Jopek <maksymilian.jopek@prym-soft.pl> | 2021-04-29 20:05:06 +0200 |
|---|---|---|
| committer | Maks Jopek <maksymilian.jopek@prym-soft.pl> | 2021-04-29 20:05:06 +0200 |
| commit | 040d5372c1033bb7c0580ad2c9b6b32f974a20c8 (patch) | |
| tree | e452aa8ad583607b87d47ef82eabf0bd7e3ab60a /frontend/ts/gameBoard.ts | |
| parent | 6baaa14bde032afa363dbdd50119a20e9f47df1c (diff) | |
| download | fia-040d5372c1033bb7c0580ad2c9b6b32f974a20c8.tar.gz fia-040d5372c1033bb7c0580ad2c9b6b32f974a20c8.tar.zst fia-040d5372c1033bb7c0580ad2c9b6b32f974a20c8.zip | |
Version 1.0
Diffstat (limited to 'frontend/ts/gameBoard.ts')
| -rw-r--r-- | frontend/ts/gameBoard.ts | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/frontend/ts/gameBoard.ts b/frontend/ts/gameBoard.ts index 14ccac6..fc8cec7 100644 --- a/frontend/ts/gameBoard.ts +++ b/frontend/ts/gameBoard.ts @@ -1,4 +1,4 @@ -import { Coordinates, GameBoard, HomesOrBases, tColors } from "../../helpers/helpersBack"; +import { Coordinates, GameBoard, HomesOrBases, OldTd, tColors } from "../../helpers/helpersBack"; import gameTable from "./gameTable.js"; import StartGame from "./startGame.js"; @@ -24,6 +24,7 @@ export default class gameBoardClass { } } } + static removeGameBoard(gameBoard: GameBoard): void { for (let square of gameBoard.map) { gameBoardClass.removeChequer({ x: square.x, y: square.y }, true); @@ -47,15 +48,19 @@ export default class gameBoardClass { td.onclick = () => null; } - static showChequer(coords: Coordinates, color: tColors): void { + static showChequer(coords: Coordinates, color: tColors, oldColor = 'void'): void { let td = gameTable.getTd(coords); if (td.dataset.count === undefined) throw new Error("td.dataset.count is undefined!!!") - - if(td.className === '') + + if (td.className === '') td.classList.add("chequer"); - - if (td.dataset.count === '0') { + + if (color === 4 && !td.className.includes(oldColor) && !td.className.includes('pink')) { + td.className = 'chequer chequer-' + StartGame.colors[color]; + td.innerHTML = ''; + td.dataset.count = '1'; + } else if (td.dataset.count === '0') { td.classList.add("chequer-" + StartGame.colors[color]); td.dataset.count = '1'; td.innerHTML = ''; @@ -64,13 +69,17 @@ export default class gameBoardClass { td.innerHTML = td.dataset.count === '1' ? '' : 'x' + td.dataset.count; } } - static hideChequer(coords: Coordinates, all = false) { + static hideChequer(coords: Coordinates, all = false, oldTd: OldTd = { className: '', innerHTML: '', count: '' }) { let td = gameTable.getTd(coords); if (td.dataset.count === undefined) throw new Error("td.dataset.count is undefined!!!") - if (all === true || ['0', '1'].includes(td.dataset.count)) { + if (oldTd.className !== '' && oldTd.count !== '') { + td.className = oldTd.className; + td.innerHTML = oldTd.innerHTML; + td.dataset.count = oldTd.count; + } else if (all === true || ['0', '1'].includes(td.dataset.count)) { td.className = 'chequer'; td.dataset.count = '0'; td.innerHTML = ''; |
