From ec5c55ccf76b74c2e217d06d6bb76ed6760cd165 Mon Sep 17 00:00:00 2001 From: IgrisBRC Date: Sun, 14 Jul 2024 14:44:19 +0530 Subject: made make move a little bit better, but still can't move the same piece twice --- public/board.js | 19 ++++++++++++++----- public/index.html | 16 ---------------- public/make_move.js | 1 - public/move.js | 2 +- public/sync_board.js | 1 - 5 files changed, 15 insertions(+), 24 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) } } diff --git a/public/index.html b/public/index.html index 312eb76..5280cde 100644 --- a/public/index.html +++ b/public/index.html @@ -13,29 +13,20 @@
-
8
-
7
-
6
-
5
-
4
-
3
-
2
-
1
-
a
@@ -47,7 +38,6 @@
-
b
@@ -59,7 +49,6 @@
-
c
@@ -71,7 +60,6 @@
-
d
@@ -83,7 +71,6 @@
-
e
@@ -95,7 +82,6 @@
-
f
@@ -107,7 +93,6 @@
-
g
@@ -119,7 +104,6 @@
-
h
diff --git a/public/make_move.js b/public/make_move.js index 562505f..16d738b 100644 --- a/public/make_move.js +++ b/public/make_move.js @@ -3,4 +3,3 @@ function make_move(board, y ,x, new_y, new_x) { board[y][x] = 0 } -make_move(board,6,4,4,4) diff --git a/public/move.js b/public/move.js index 0c441c2..51b585c 100644 --- a/public/move.js +++ b/public/move.js @@ -3,7 +3,7 @@ let board = [ [-6, -6, -6, -6, -6, -6, -6, -6], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 2, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [6, 6, 6, 6, 6, 6, 6, 6], [3, 5, 4, 2, 1, 4, 5, 3], diff --git a/public/sync_board.js b/public/sync_board.js index c56cb77..7044db2 100644 --- a/public/sync_board.js +++ b/public/sync_board.js @@ -14,5 +14,4 @@ function sync_board() { piece.append(table[Math.abs(board[i][j])]) } } - console.log(board) } -- cgit v1.2.3