Raven7 commited on
Commit
4ebde63
·
verified ·
1 Parent(s): 54b2acd

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +30 -31
index.html CHANGED
@@ -20,32 +20,28 @@
20
  }
21
 
22
  body {
23
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
24
  background: var(--primary-dark);
25
  color: #ecf0f1;
26
- min-height: 100vh;
27
  display: flex;
 
 
 
28
  }
29
 
30
  .container {
31
  display: grid;
32
  grid-template-columns: var(--board-size) 300px;
33
  gap: 2rem;
34
- margin: auto;
35
- padding: 2rem;
36
  background: var(--primary-light);
 
37
  border-radius: 1rem;
38
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
39
  }
40
 
41
- .board-container {
42
  width: var(--board-size);
43
  height: var(--board-size);
44
- }
45
-
46
- .chessboard {
47
- width: 100%;
48
- height: 100%;
49
  display: grid;
50
  grid-template-columns: repeat(8, 1fr);
51
  grid-template-rows: repeat(8, 1fr);
@@ -56,7 +52,6 @@
56
  align-items: center;
57
  justify-content: center;
58
  font-size: calc(var(--square-size) * 0.7);
59
- cursor: pointer;
60
  }
61
 
62
  .white { background: #f0d9b5; }
@@ -68,19 +63,14 @@
68
  user-select: none;
69
  }
70
 
71
- @media (max-width: 1024px) {
72
- .container {
73
- grid-template-columns: 1fr;
74
- }
75
- }
76
  </style>
77
  </head>
78
  <body>
79
  <div class="container">
80
- <div class="board-container">
81
- <div class="chessboard" id="board"></div>
82
- </div>
83
- <div class="controls">
84
  <h3>Position Analysis</h3>
85
  <p id="status">White to move</p>
86
  <button onclick="resetBoard()">Reset Board</button>
@@ -119,12 +109,13 @@
119
  square.className = `square ${(row + col) % 2 === 0 ? 'white' : 'black'}`;
120
  square.dataset.row = row;
121
  square.dataset.col = col;
 
122
  square.onclick = () => this.handleSquareClick(row, col);
123
 
124
  const piece = this.board[row][col];
125
  if (piece) {
126
  const pieceElement = document.createElement('div');
127
- pieceElement.className = 'piece';
128
  pieceElement.textContent = piece;
129
  square.appendChild(pieceElement);
130
  }
@@ -135,30 +126,38 @@
135
  }
136
 
137
  handleSquareClick(row, col) {
 
 
 
 
138
  if (this.selectedPiece) {
139
- this.movePiece(this.selectedPiece.row, this.selectedPiece.col, row, col);
140
  this.selectedPiece = null;
141
- } else if (this.board[row][col]) {
 
142
  this.selectedPiece = { row, col };
143
- this.highlightSquare(row, col);
 
144
  }
145
  }
146
 
147
- highlightSquare(row, col) {
148
- document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected'));
149
- const square = document.querySelector(`.square[data-row="${row}"][data-col="${col}"]`);
150
- square.classList.add('selected');
 
 
 
151
  }
152
 
153
  movePiece(fromRow, fromCol, toRow, toCol) {
154
- const piece = this.board[fromRow][fromCol];
155
  this.board[fromRow][fromCol] = null;
156
- this.board[toRow][toCol] = piece;
157
 
158
  this.currentPlayer = this.currentPlayer === 'white' ? 'black' : 'white';
159
  document.getElementById('status').textContent =
160
  `${this.currentPlayer.charAt(0).toUpperCase() + this.currentPlayer.slice(1)} to move`;
161
-
162
  this.initializeBoard();
163
  }
164
  }
 
20
  }
21
 
22
  body {
23
+ font-family: Arial, sans-serif;
24
  background: var(--primary-dark);
25
  color: #ecf0f1;
 
26
  display: flex;
27
+ justify-content: center;
28
+ align-items: center;
29
+ min-height: 100vh;
30
  }
31
 
32
  .container {
33
  display: grid;
34
  grid-template-columns: var(--board-size) 300px;
35
  gap: 2rem;
 
 
36
  background: var(--primary-light);
37
+ padding: 2rem;
38
  border-radius: 1rem;
39
  box-shadow: 0 10px 20px rgba(0,0,0,0.2);
40
  }
41
 
42
+ .chessboard {
43
  width: var(--board-size);
44
  height: var(--board-size);
 
 
 
 
 
45
  display: grid;
46
  grid-template-columns: repeat(8, 1fr);
47
  grid-template-rows: repeat(8, 1fr);
 
52
  align-items: center;
53
  justify-content: center;
54
  font-size: calc(var(--square-size) * 0.7);
 
55
  }
56
 
57
  .white { background: #f0d9b5; }
 
63
  user-select: none;
64
  }
65
 
66
+ .piece.white { color: #fff; }
67
+ .piece.black { color: #000; }
 
 
 
68
  </style>
69
  </head>
70
  <body>
71
  <div class="container">
72
+ <div class="chessboard" id="board"></div>
73
+ <div>
 
 
74
  <h3>Position Analysis</h3>
75
  <p id="status">White to move</p>
76
  <button onclick="resetBoard()">Reset Board</button>
 
109
  square.className = `square ${(row + col) % 2 === 0 ? 'white' : 'black'}`;
110
  square.dataset.row = row;
111
  square.dataset.col = col;
112
+
113
  square.onclick = () => this.handleSquareClick(row, col);
114
 
115
  const piece = this.board[row][col];
116
  if (piece) {
117
  const pieceElement = document.createElement('div');
118
+ pieceElement.className = `piece ${row < 2 ? 'black' : 'white'}`;
119
  pieceElement.textContent = piece;
120
  square.appendChild(pieceElement);
121
  }
 
126
  }
127
 
128
  handleSquareClick(row, col) {
129
+ const square = document.querySelector(`[data-row="${row}"][data-col="${col}"]`);
130
+ const piece = this.board[row][col];
131
+ const pieceColor = row < 2 ? 'black' : row > 5 ? 'white' : null;
132
+
133
  if (this.selectedPiece) {
134
+ this.tryMove(this.selectedPiece.row, this.selectedPiece.col, row, col);
135
  this.selectedPiece = null;
136
+ document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected'));
137
+ } else if (piece && pieceColor === this.currentPlayer) {
138
  this.selectedPiece = { row, col };
139
+ document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected'));
140
+ square.classList.add('selected');
141
  }
142
  }
143
 
144
+ tryMove(fromRow, fromCol, toRow, toCol) {
145
+ const targetPiece = this.board[toRow][toCol];
146
+ const targetColor = toRow < 2 ? 'black' : toRow > 5 ? 'white' : null;
147
+
148
+ if (targetColor !== this.currentPlayer) {
149
+ this.movePiece(fromRow, fromCol, toRow, toCol);
150
+ }
151
  }
152
 
153
  movePiece(fromRow, fromCol, toRow, toCol) {
154
+ this.board[toRow][toCol] = this.board[fromRow][fromCol];
155
  this.board[fromRow][fromCol] = null;
 
156
 
157
  this.currentPlayer = this.currentPlayer === 'white' ? 'black' : 'white';
158
  document.getElementById('status').textContent =
159
  `${this.currentPlayer.charAt(0).toUpperCase() + this.currentPlayer.slice(1)} to move`;
160
+
161
  this.initializeBoard();
162
  }
163
  }