Spaces:
Running
Running
Update index.html
Browse files- index.html +47 -83
index.html
CHANGED
@@ -9,10 +9,8 @@
|
|
9 |
--board-size: min(80vh, 600px);
|
10 |
--square-size: calc(var(--board-size) / 8);
|
11 |
--primary-dark: #2c3e50;
|
12 |
-
--primary-light: #
|
13 |
--highlight: #f1c40f;
|
14 |
-
--move-highlight: rgba(46, 204, 113, 0.4);
|
15 |
-
--check-highlight: rgba(231, 76, 60, 0.4);
|
16 |
}
|
17 |
|
18 |
* {
|
@@ -43,7 +41,6 @@
|
|
43 |
.board-container {
|
44 |
width: var(--board-size);
|
45 |
height: var(--board-size);
|
46 |
-
position: relative;
|
47 |
}
|
48 |
|
49 |
.chessboard {
|
@@ -52,9 +49,6 @@
|
|
52 |
display: grid;
|
53 |
grid-template-columns: repeat(8, 1fr);
|
54 |
grid-template-rows: repeat(8, 1fr);
|
55 |
-
border: 4px solid #2c3e50;
|
56 |
-
border-radius: 4px;
|
57 |
-
overflow: hidden;
|
58 |
}
|
59 |
|
60 |
.square {
|
@@ -63,46 +57,22 @@
|
|
63 |
justify-content: center;
|
64 |
font-size: calc(var(--square-size) * 0.7);
|
65 |
cursor: pointer;
|
66 |
-
transition: all 0.2s;
|
67 |
-
position: relative;
|
68 |
-
user-select: none;
|
69 |
-
}
|
70 |
-
|
71 |
-
.white { background: #e0c48f; }
|
72 |
-
.black { background: #b4835a; }
|
73 |
-
|
74 |
-
.square.selected {
|
75 |
-
background: var(--highlight) !important;
|
76 |
}
|
77 |
|
78 |
-
.
|
79 |
-
|
80 |
-
|
81 |
-
color: rgba(0,0,0,0.3);
|
82 |
-
font-size: 2em;
|
83 |
-
}
|
84 |
-
|
85 |
-
.square.attack-move::after {
|
86 |
-
content: '';
|
87 |
-
position: absolute;
|
88 |
-
width: 100%;
|
89 |
-
height: 100%;
|
90 |
-
border: 2px solid rgba(231, 76, 60, 0.6);
|
91 |
-
border-radius: 50%;
|
92 |
-
}
|
93 |
|
94 |
.piece {
|
95 |
-
width: 100%;
|
96 |
-
height: 100%;
|
97 |
-
display: flex;
|
98 |
-
align-items: center;
|
99 |
-
justify-content: center;
|
100 |
font-size: calc(var(--square-size) * 0.7);
|
101 |
-
|
102 |
}
|
103 |
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
106 |
</style>
|
107 |
</head>
|
108 |
<body>
|
@@ -110,6 +80,11 @@
|
|
110 |
<div class="board-container">
|
111 |
<div class="chessboard" id="board"></div>
|
112 |
</div>
|
|
|
|
|
|
|
|
|
|
|
113 |
</div>
|
114 |
|
115 |
<script>
|
@@ -123,14 +98,14 @@
|
|
123 |
|
124 |
createInitialBoard() {
|
125 |
return [
|
126 |
-
['
|
127 |
-
['
|
128 |
[null, null, null, null, null, null, null, null],
|
129 |
[null, null, null, null, null, null, null, null],
|
130 |
[null, null, null, null, null, null, null, null],
|
131 |
[null, null, null, null, null, null, null, null],
|
132 |
-
['
|
133 |
-
['
|
134 |
];
|
135 |
}
|
136 |
|
@@ -144,13 +119,13 @@
|
|
144 |
square.className = `square ${(row + col) % 2 === 0 ? 'white' : 'black'}`;
|
145 |
square.dataset.row = row;
|
146 |
square.dataset.col = col;
|
147 |
-
square.onclick = (
|
148 |
|
149 |
const piece = this.board[row][col];
|
150 |
if (piece) {
|
151 |
const pieceElement = document.createElement('div');
|
152 |
-
pieceElement.className =
|
153 |
-
pieceElement.textContent =
|
154 |
square.appendChild(pieceElement);
|
155 |
}
|
156 |
|
@@ -159,54 +134,43 @@
|
|
159 |
}
|
160 |
}
|
161 |
|
162 |
-
|
163 |
-
const symbols = {
|
164 |
-
'P': 'β', 'p': 'β',
|
165 |
-
'R': 'β', 'r': 'β',
|
166 |
-
'N': 'β', 'n': 'β',
|
167 |
-
'B': 'β', 'b': 'β',
|
168 |
-
'Q': 'β', 'q': 'β',
|
169 |
-
'K': 'β', 'k': 'β'
|
170 |
-
};
|
171 |
-
return symbols[piece] || '';
|
172 |
-
}
|
173 |
-
|
174 |
-
handleSquareClick(event) {
|
175 |
-
const square = event.target.closest('.square');
|
176 |
-
const row = parseInt(square.dataset.row);
|
177 |
-
const col = parseInt(square.dataset.col);
|
178 |
-
|
179 |
-
const piece = this.board[row][col];
|
180 |
-
|
181 |
if (this.selectedPiece) {
|
182 |
-
this.
|
183 |
-
|
184 |
-
|
|
|
|
|
185 |
}
|
186 |
}
|
187 |
|
188 |
-
|
189 |
-
return (this.currentPlayer === 'white' && piece === piece.toUpperCase()) ||
|
190 |
-
(this.currentPlayer === 'black' && piece === piece.toLowerCase());
|
191 |
-
}
|
192 |
-
|
193 |
-
selectPiece(row, col) {
|
194 |
-
this.selectedPiece = { row, col };
|
195 |
document.querySelectorAll('.square').forEach(sq => sq.classList.remove('selected'));
|
196 |
-
document.querySelector(
|
|
|
197 |
}
|
198 |
|
199 |
-
|
200 |
-
const
|
201 |
-
this.board[
|
202 |
-
this.board[
|
|
|
203 |
this.currentPlayer = this.currentPlayer === 'white' ? 'black' : 'white';
|
204 |
-
|
|
|
|
|
205 |
this.initializeBoard();
|
206 |
}
|
207 |
}
|
208 |
|
209 |
-
new ChessGame();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
</script>
|
211 |
</body>
|
212 |
</html>
|
|
|
9 |
--board-size: min(80vh, 600px);
|
10 |
--square-size: calc(var(--board-size) / 8);
|
11 |
--primary-dark: #2c3e50;
|
12 |
+
--primary-light: #34495e;
|
13 |
--highlight: #f1c40f;
|
|
|
|
|
14 |
}
|
15 |
|
16 |
* {
|
|
|
41 |
.board-container {
|
42 |
width: var(--board-size);
|
43 |
height: var(--board-size);
|
|
|
44 |
}
|
45 |
|
46 |
.chessboard {
|
|
|
49 |
display: grid;
|
50 |
grid-template-columns: repeat(8, 1fr);
|
51 |
grid-template-rows: repeat(8, 1fr);
|
|
|
|
|
|
|
52 |
}
|
53 |
|
54 |
.square {
|
|
|
57 |
justify-content: center;
|
58 |
font-size: calc(var(--square-size) * 0.7);
|
59 |
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
+
.white { background: #f0d9b5; }
|
63 |
+
.black { background: #b58863; }
|
64 |
+
.selected { background: var(--highlight); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
.piece {
|
|
|
|
|
|
|
|
|
|
|
67 |
font-size: calc(var(--square-size) * 0.7);
|
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>
|
|
|
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>
|
87 |
+
</div>
|
88 |
</div>
|
89 |
|
90 |
<script>
|
|
|
98 |
|
99 |
createInitialBoard() {
|
100 |
return [
|
101 |
+
['β', 'β', 'β', 'β', 'β', 'β', 'β', 'β'],
|
102 |
+
['β', 'β', 'β', 'β', 'β', 'β', 'β', 'β'],
|
103 |
[null, null, null, null, null, null, null, null],
|
104 |
[null, null, null, null, null, null, null, null],
|
105 |
[null, null, null, null, null, null, null, null],
|
106 |
[null, null, null, null, null, null, null, null],
|
107 |
+
['β', 'β', 'β', 'β', 'β', 'β', 'β', 'β'],
|
108 |
+
['β', 'β', 'β', 'β', 'β', 'β', 'β', 'β']
|
109 |
];
|
110 |
}
|
111 |
|
|
|
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 |
}
|
131 |
|
|
|
134 |
}
|
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 |
}
|
165 |
|
166 |
+
const game = new ChessGame();
|
167 |
+
|
168 |
+
function resetBoard() {
|
169 |
+
game.board = game.createInitialBoard();
|
170 |
+
game.currentPlayer = 'white';
|
171 |
+
game.initializeBoard();
|
172 |
+
document.getElementById('status').textContent = 'White to move';
|
173 |
+
}
|
174 |
</script>
|
175 |
</body>
|
176 |
</html>
|