Raven7 commited on
Commit
4b1124a
·
verified ·
1 Parent(s): 7ad8ecd

Update index.html

Browse files
Files changed (1) hide show
  1. 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 moves = this.getPieceMoves(this.selectedPiece.row, this.selectedPiece.col);
201
- const isValidMove = moves.some(move => move.row === toRow && move.col === toCol);
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
- const piece = this.board[fromRow][fromCol];
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();