diff options
author | IgrisBRC <[email protected]> | 2024-07-14 14:44:19 +0530 |
---|---|---|
committer | IgrisBRC <[email protected]> | 2024-07-14 14:44:19 +0530 |
commit | ec5c55ccf76b74c2e217d06d6bb76ed6760cd165 (patch) | |
tree | 23a0a710408b737be76277d652b5ba68b903147a /public/board.js | |
parent | 4194b03e980ac68e0fd07e183189fbe93dfefdce (diff) |
made make move a little bit better, but still can't move the same piece twice
Diffstat (limited to 'public/board.js')
-rw-r--r-- | public/board.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/public/board.js b/public/board.js index ca46335..5738eab 100644 --- a/public/board.js +++ b/public/board.js @@ -22,21 +22,21 @@ for (let i = 0; i < squares.length; i++) { } for (let i = 0; i < moves.length; i++) { + let hlsquare = document.getElementById(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`) hlsquare.classList.add('highlight') - hlsquare.onclick = handle_move(id, hlsquare.id) previously_highlighted_squares.push(`${alphabet[moves[i][1]]}${8 - moves[i][0]}`) } + + let hlsquare = document.getElementsByClassName('highlight') + for (let i = 0; i < hlsquare.length; i++) { + } } } -//let handle_move = () => { -// console.log('move') -//} - function handle_move(from_id, id) { return function() { let table = { 1: 'K', 2: 'Q', 3: 'R', 4: 'B', 5: 'N', 6: 'p' } @@ -48,6 +48,12 @@ function handle_move(from_id, id) { from_element.removeChild(from_element.firstChild) } + for (let i = 0; i < previously_highlighted_squares.length; i++) { + let prev = document.getElementById(previously_highlighted_squares[i]) + prev.classList.remove('highlight') + prev.onclick = null + } + let new_element = document.getElementById(id) let piece = document.createElement('p') piece.classList.add(board[8 - id.charAt(1)][id.charCodeAt(0) - 97] > 0 ? 'w' : 'b', 'piece') @@ -55,5 +61,8 @@ function handle_move(from_id, id) { piece.append(table[Math.abs(board[8 - id.charAt(1)][id.charCodeAt(0) - 97])]) to_move = !to_move + + console.log(from_id, id) + console.log(board) } } |