summaryrefslogtreecommitdiff
path: root/public/board.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/board.js')
-rw-r--r--public/board.js19
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)
}
}