Spaces:
Running
Running
Update index.html
Browse files- index.html +4 -10
index.html
CHANGED
@@ -193,24 +193,18 @@
|
|
193 |
document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected', 'valid-move', 'attack-move'));
|
194 |
document.querySelector(`[data-row="${row}"][data-col="${col}"]`).classList.add('selected');
|
195 |
this.selectedPiece = { row, col };
|
196 |
-
this.showValidMoves(row, col);
|
197 |
}
|
198 |
|
199 |
tryMove(toRow, toCol) {
|
200 |
-
const
|
201 |
-
const
|
202 |
-
|
203 |
-
if (isValidMove) {
|
204 |
-
this.makeMove(this.selectedPiece.row, this.selectedPiece.col, toRow, toCol);
|
205 |
-
}
|
206 |
-
document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected', 'valid-move', 'attack-move'));
|
207 |
this.selectedPiece = null;
|
208 |
}
|
209 |
|
210 |
makeMove(fromRow, fromCol, toRow, toCol) {
|
211 |
-
|
212 |
this.board[fromRow][fromCol] = null;
|
213 |
-
this.board[toRow][toCol] = piece;
|
214 |
this.currentPlayer = this.currentPlayer === 'white' ? 'black' : 'white';
|
215 |
document.getElementById('status').textContent = `${this.currentPlayer} to move`;
|
216 |
this.initializeBoard();
|
|
|
193 |
document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected', 'valid-move', 'attack-move'));
|
194 |
document.querySelector(`[data-row="${row}"][data-col="${col}"]`).classList.add('selected');
|
195 |
this.selectedPiece = { row, col };
|
|
|
196 |
}
|
197 |
|
198 |
tryMove(toRow, toCol) {
|
199 |
+
const fromRow = this.selectedPiece.row;
|
200 |
+
const fromCol = this.selectedPiece.col;
|
201 |
+
this.makeMove(fromRow, fromCol, toRow, toCol);
|
|
|
|
|
|
|
|
|
202 |
this.selectedPiece = null;
|
203 |
}
|
204 |
|
205 |
makeMove(fromRow, fromCol, toRow, toCol) {
|
206 |
+
this.board[toRow][toCol] = this.board[fromRow][fromCol];
|
207 |
this.board[fromRow][fromCol] = null;
|
|
|
208 |
this.currentPlayer = this.currentPlayer === 'white' ? 'black' : 'white';
|
209 |
document.getElementById('status').textContent = `${this.currentPlayer} to move`;
|
210 |
this.initializeBoard();
|