diff options
author | IgrisBRC <[email protected]> | 2024-07-14 07:47:23 +0530 |
---|---|---|
committer | IgrisBRC <[email protected]> | 2024-07-14 07:47:23 +0530 |
commit | a734e0af70a14dc8d635ab988c82e1a2e0b49836 (patch) | |
tree | 62b3023054d9fc7ba0a89cb0d0f4dbd27d7a9bc8 /public/game.js | |
parent | 2b0cdea28c841040fd872b2b1837b1e0639d6df0 (diff) |
fixed critical error in highlighting, the moves were mapped mirrored from the board
Diffstat (limited to 'public/game.js')
-rw-r--r-- | public/game.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/public/game.js b/public/game.js index 05ddc66..e5740de 100644 --- a/public/game.js +++ b/public/game.js @@ -3,7 +3,7 @@ const alphabet = 'abcdefgh' for (let i = 0; i < 8; i++) { for (let j = 0; j < 8; j++) { - let square = document.getElementById(`${alphabet.charAt(j)}${i + 1}`) + let square = document.getElementById(`${alphabet.charAt(j)}${8 - i}`) let piece = document.createElement('p') piece.classList.add('piece') @@ -73,9 +73,9 @@ for (let i = 0; i < 8; i++) { } } -let squares = document.getElementsByClassName('box') +let squares = document.getElementsByClassName('square') -let previously_highlighted_squares = ["dummy"] +let previously_highlighted_squares = ['dummy'] for (let i = 0; i < squares.length; i++) { @@ -87,15 +87,17 @@ for (let i = 0; i < squares.length; i++) { square.push(8 - id.charAt(1)) square.push(id.charAt(0).charCodeAt(0) - 97) + let moves = move(board, square[0], square[1]) for (let i = 0; i < previously_highlighted_squares.length; i++) { + //document.getElementById(previously_highlighted_squares[i]).style.backgroundColor = 'transparent' document.getElementById(previously_highlighted_squares[i]).classList.remove('highlight') } - for (let i = 0; i < moves.length; i++) { + //document.getElementById(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`).style.backgroundColor = 'yellow' document.getElementById(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`).classList.add('highlight') previously_highlighted_squares.push(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`) } |