openfree commited on
Commit
7b6ac6c
1 Parent(s): 1e433a1

Upload index.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +327 -18
index.html CHANGED
@@ -1,19 +1,328 @@
1
- <!doctype html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Jewel Match</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ background: #111;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ min-height: 100vh;
15
+ font-family: Arial, sans-serif;
16
+ }
17
+ #gameContainer {
18
+ position: relative;
19
+ }
20
+ canvas {
21
+ border: 2px solid #333;
22
+ box-shadow: 0 0 20px rgba(0,0,0,0.5);
23
+ }
24
+ #ui {
25
+ position: absolute;
26
+ top: 10px;
27
+ left: 10px;
28
+ color: white;
29
+ font-size: 20px;
30
+ }
31
+ #score {
32
+ margin-bottom: 10px;
33
+ }
34
+ </style>
35
+ </head>
36
+ <body>
37
+ <div id="gameContainer">
38
+ <canvas id="gameCanvas"></canvas>
39
+ <div id="ui">
40
+ <div id="score">Score: 0</div>
41
+ <div id="moves">Moves: 30</div>
42
+ </div>
43
+ </div>
44
+
45
+ <script>
46
+ const canvas = document.getElementById('gameCanvas');
47
+ const ctx = canvas.getContext('2d');
48
+ const GRID_SIZE = 8;
49
+ const CELL_SIZE = 70;
50
+ const ANIMATION_SPEED = 0.15;
51
+
52
+ canvas.width = GRID_SIZE * CELL_SIZE;
53
+ canvas.height = GRID_SIZE * CELL_SIZE;
54
+
55
+ const GEMS = {
56
+ RUBY: {color: '#ff0000', highlight: '#ff6666'},
57
+ SAPPHIRE: {color: '#0000ff', highlight: '#6666ff'},
58
+ EMERALD: {color: '#00ff00', highlight: '#66ff66'},
59
+ DIAMOND: {color: '#ffffff', highlight: '#aaaaaa'},
60
+ TOPAZ: {color: '#ffff00', highlight: '#ffff66'},
61
+ AMETHYST: {color: '#ff00ff', highlight: '#ff66ff'}
62
+ };
63
+
64
+ let score = 0;
65
+ let moves = 30;
66
+ let board = [];
67
+ let selectedGem = null;
68
+ let animations = [];
69
+ let isAnimating = false;
70
+
71
+ class Gem {
72
+ constructor(type, row, col) {
73
+ this.type = type;
74
+ this.row = row;
75
+ this.col = col;
76
+ this.x = col * CELL_SIZE;
77
+ this.y = row * CELL_SIZE;
78
+ this.targetX = this.x;
79
+ this.targetY = this.y;
80
+ this.scale = 1;
81
+ this.alpha = 1;
82
+ }
83
+
84
+ draw() {
85
+ ctx.save();
86
+ ctx.globalAlpha = this.alpha;
87
+ ctx.translate(this.x + CELL_SIZE/2, this.y + CELL_SIZE/2);
88
+ ctx.scale(this.scale, this.scale);
89
+
90
+ // Draw gem base
91
+ ctx.beginPath();
92
+ ctx.arc(0, 0, CELL_SIZE/2 - 10, 0, Math.PI * 2);
93
+ ctx.fillStyle = GEMS[this.type].color;
94
+ ctx.fill();
95
+
96
+ // Draw highlight
97
+ ctx.beginPath();
98
+ ctx.arc(-10, -10, 10, 0, Math.PI * 2);
99
+ ctx.fillStyle = GEMS[this.type].highlight;
100
+ ctx.fill();
101
+
102
+ ctx.restore();
103
+ }
104
+
105
+ update() {
106
+ if(this.x !== this.targetX) {
107
+ this.x += (this.targetX - this.x) * ANIMATION_SPEED;
108
+ }
109
+ if(this.y !== this.targetY) {
110
+ this.y += (this.targetY - this.y) * ANIMATION_SPEED;
111
+ }
112
+ }
113
+ }
114
+
115
+ function initBoard() {
116
+ for(let row = 0; row < GRID_SIZE; row++) {
117
+ board[row] = [];
118
+ for(let col = 0; col < GRID_SIZE; col++) {
119
+ const gemTypes = Object.keys(GEMS);
120
+ const randomType = gemTypes[Math.floor(Math.random() * gemTypes.length)];
121
+ board[row][col] = new Gem(randomType, row, col);
122
+ }
123
+ }
124
+ }
125
+
126
+ function draw() {
127
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
128
+
129
+ // Draw board
130
+ for(let row = 0; row < GRID_SIZE; row++) {
131
+ for(let col = 0; col < GRID_SIZE; col++) {
132
+ if(board[row][col]) {
133
+ board[row][col].draw();
134
+ }
135
+ }
136
+ }
137
+
138
+ // Draw selected gem highlight
139
+ if(selectedGem) {
140
+ ctx.strokeStyle = '#fff';
141
+ ctx.lineWidth = 3;
142
+ ctx.strokeRect(
143
+ selectedGem.col * CELL_SIZE,
144
+ selectedGem.row * CELL_SIZE,
145
+ CELL_SIZE,
146
+ CELL_SIZE
147
+ );
148
+ }
149
+
150
+ requestAnimationFrame(draw);
151
+ }
152
+
153
+ function update() {
154
+ for(let row = 0; row < GRID_SIZE; row++) {
155
+ for(let col = 0; col < GRID_SIZE; col++) {
156
+ if(board[row][col]) {
157
+ board[row][col].update();
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ function handleClick(e) {
164
+ if(isAnimating) return;
165
+
166
+ const rect = canvas.getBoundingClientRect();
167
+ const x = e.clientX - rect.left;
168
+ const y = e.clientY - rect.top;
169
+
170
+ const col = Math.floor(x / CELL_SIZE);
171
+ const row = Math.floor(y / CELL_SIZE);
172
+
173
+ if(col >= 0 && col < GRID_SIZE && row >= 0 && row < GRID_SIZE) {
174
+ if(!selectedGem) {
175
+ selectedGem = board[row][col];
176
+ } else {
177
+ // Check if adjacent
178
+ const rowDiff = Math.abs(selectedGem.row - row);
179
+ const colDiff = Math.abs(selectedGem.col - col);
180
+
181
+ if((rowDiff === 1 && colDiff === 0) || (rowDiff === 0 && colDiff === 1)) {
182
+ swapGems(selectedGem, board[row][col]);
183
+ }
184
+ selectedGem = null;
185
+ }
186
+ }
187
+ }
188
+
189
+ function swapGems(gem1, gem2) {
190
+ const tempX = gem1.targetX;
191
+ const tempY = gem1.targetY;
192
+ const tempRow = gem1.row;
193
+ const tempCol = gem1.col;
194
+
195
+ gem1.targetX = gem2.targetX;
196
+ gem1.targetY = gem2.targetY;
197
+ gem1.row = gem2.row;
198
+ gem1.col = gem2.col;
199
+
200
+ gem2.targetX = tempX;
201
+ gem2.targetY = tempY;
202
+ gem2.row = tempRow;
203
+ gem2.col = tempCol;
204
+
205
+ board[gem1.row][gem1.col] = gem1;
206
+ board[gem2.row][gem2.col] = gem2;
207
+
208
+ moves--;
209
+ document.getElementById('moves').textContent = `Moves: ${moves}`;
210
+
211
+ setTimeout(checkMatches, 300);
212
+ }
213
+
214
+ function checkMatches() {
215
+ let matches = [];
216
+
217
+ // Check horizontal matches
218
+ for(let row = 0; row < GRID_SIZE; row++) {
219
+ let matchCount = 1;
220
+ let matchType = board[row][0]?.type;
221
+
222
+ for(let col = 1; col < GRID_SIZE; col++) {
223
+ if(board[row][col]?.type === matchType) {
224
+ matchCount++;
225
+ } else {
226
+ if(matchCount >= 3) {
227
+ for(let i = col-matchCount; i < col; i++) {
228
+ matches.push({row, col: i});
229
+ }
230
+ }
231
+ matchCount = 1;
232
+ matchType = board[row][col]?.type;
233
+ }
234
+ }
235
+ if(matchCount >= 3) {
236
+ for(let i = GRID_SIZE-matchCount; i < GRID_SIZE; i++) {
237
+ matches.push({row, col: i});
238
+ }
239
+ }
240
+ }
241
+
242
+ // Check vertical matches
243
+ for(let col = 0; col < GRID_SIZE; col++) {
244
+ let matchCount = 1;
245
+ let matchType = board[0][col]?.type;
246
+
247
+ for(let row = 1; row < GRID_SIZE; row++) {
248
+ if(board[row][col]?.type === matchType) {
249
+ matchCount++;
250
+ } else {
251
+ if(matchCount >= 3) {
252
+ for(let i = row-matchCount; i < row; i++) {
253
+ matches.push({row: i, col});
254
+ }
255
+ }
256
+ matchCount = 1;
257
+ matchType = board[row][col]?.type;
258
+ }
259
+ }
260
+ if(matchCount >= 3) {
261
+ for(let i = GRID_SIZE-matchCount; i < GRID_SIZE; i++) {
262
+ matches.push({row: i, col});
263
+ }
264
+ }
265
+ }
266
+
267
+ if(matches.length > 0) {
268
+ removeMatches(matches);
269
+ }
270
+ }
271
+
272
+ function removeMatches(matches) {
273
+ isAnimating = true;
274
+
275
+ // Remove matched gems
276
+ matches.forEach(({row, col}) => {
277
+ if(board[row][col]) {
278
+ score += 10;
279
+ document.getElementById('score').textContent = `Score: ${score}`;
280
+ board[row][col] = null;
281
+ }
282
+ });
283
+
284
+ // Drop remaining gems
285
+ for(let col = 0; col < GRID_SIZE; col++) {
286
+ let emptySpaces = 0;
287
+ for(let row = GRID_SIZE-1; row >= 0; row--) {
288
+ if(!board[row][col]) {
289
+ emptySpaces++;
290
+ } else if(emptySpaces > 0) {
291
+ const gem = board[row][col];
292
+ gem.row += emptySpaces;
293
+ gem.targetY = gem.row * CELL_SIZE;
294
+ board[gem.row][col] = gem;
295
+ board[row][col] = null;
296
+ }
297
+ }
298
+
299
+ // Fill empty spaces with new gems
300
+ for(let row = emptySpaces-1; row >= 0; row--) {
301
+ const gemTypes = Object.keys(GEMS);
302
+ const randomType = gemTypes[Math.floor(Math.random() * gemTypes.length)];
303
+ const newGem = new Gem(randomType, row, col);
304
+ newGem.y = -CELL_SIZE;
305
+ newGem.targetY = row * CELL_SIZE;
306
+ board[row][col] = newGem;
307
+ }
308
+ }
309
+
310
+ setTimeout(() => {
311
+ isAnimating = false;
312
+ checkMatches();
313
+ }, 500);
314
+ }
315
+
316
+ canvas.addEventListener('click', handleClick);
317
+
318
+ function gameLoop() {
319
+ update();
320
+ requestAnimationFrame(gameLoop);
321
+ }
322
+
323
+ initBoard();
324
+ gameLoop();
325
+ draw();
326
+ </script>
327
+ </body>
328
+ </html>