drbinna commited on
Commit
6bef773
·
verified ·
1 Parent(s): 5848ead

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +493 -19
index.html CHANGED
@@ -1,19 +1,493 @@
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 lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Fraction Factory</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: 'Arial', sans-serif;
16
+ background: #000000;
17
+ display: flex;
18
+ justify-content: center;
19
+ align-items: center;
20
+ min-height: 100vh;
21
+ padding: 20px;
22
+ }
23
+
24
+ .game-container {
25
+ background: white;
26
+ border-radius: 20px;
27
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
28
+ padding: 30px;
29
+ max-width: 900px;
30
+ width: 100%;
31
+ }
32
+
33
+ .header {
34
+ text-align: center;
35
+ margin-bottom: 20px;
36
+ }
37
+
38
+ .header h1 {
39
+ color: #667eea;
40
+ font-size: 2.5em;
41
+ margin-bottom: 10px;
42
+ }
43
+
44
+ .header p {
45
+ color: #666;
46
+ font-size: 1.1em;
47
+ }
48
+
49
+ .stats {
50
+ display: flex;
51
+ justify-content: space-around;
52
+ margin-bottom: 20px;
53
+ padding: 15px;
54
+ background: #f0f0f0;
55
+ border-radius: 10px;
56
+ }
57
+
58
+ .stat {
59
+ text-align: center;
60
+ }
61
+
62
+ .stat-label {
63
+ font-size: 0.9em;
64
+ color: #666;
65
+ margin-bottom: 5px;
66
+ }
67
+
68
+ .stat-value {
69
+ font-size: 1.8em;
70
+ font-weight: bold;
71
+ color: #667eea;
72
+ }
73
+
74
+ .game-canvas {
75
+ width: 100%;
76
+ border: 3px solid #667eea;
77
+ border-radius: 10px;
78
+ background: #e8f4f8;
79
+ display: block;
80
+ }
81
+
82
+ .controls {
83
+ margin-top: 20px;
84
+ display: flex;
85
+ gap: 10px;
86
+ flex-wrap: wrap;
87
+ justify-content: center;
88
+ }
89
+
90
+ .answer-btn {
91
+ padding: 15px 30px;
92
+ font-size: 1.2em;
93
+ font-weight: bold;
94
+ border: 3px solid #667eea;
95
+ background: white;
96
+ color: #667eea;
97
+ border-radius: 10px;
98
+ cursor: pointer;
99
+ transition: all 0.3s;
100
+ min-width: 120px;
101
+ }
102
+
103
+ .answer-btn:hover {
104
+ background: #667eea;
105
+ color: white;
106
+ transform: translateY(-2px);
107
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
108
+ }
109
+
110
+ .answer-btn:active {
111
+ transform: translateY(0);
112
+ }
113
+
114
+ .answer-btn.correct {
115
+ background: #4ade80;
116
+ border-color: #4ade80;
117
+ color: white;
118
+ }
119
+
120
+ .answer-btn.wrong {
121
+ background: #f87171;
122
+ border-color: #f87171;
123
+ color: white;
124
+ }
125
+
126
+ .start-screen, .game-over-screen {
127
+ text-align: center;
128
+ padding: 40px;
129
+ }
130
+
131
+ .start-btn, .restart-btn {
132
+ padding: 20px 50px;
133
+ font-size: 1.5em;
134
+ font-weight: bold;
135
+ background: #667eea;
136
+ color: white;
137
+ border: none;
138
+ border-radius: 15px;
139
+ cursor: pointer;
140
+ transition: all 0.3s;
141
+ margin-top: 20px;
142
+ }
143
+
144
+ .start-btn:hover, .restart-btn:hover {
145
+ background: #764ba2;
146
+ transform: scale(1.05);
147
+ }
148
+
149
+ .feedback {
150
+ text-align: center;
151
+ margin-top: 15px;
152
+ font-size: 1.2em;
153
+ font-weight: bold;
154
+ min-height: 30px;
155
+ }
156
+
157
+ .feedback.correct {
158
+ color: #4ade80;
159
+ }
160
+
161
+ .feedback.wrong {
162
+ color: #f87171;
163
+ }
164
+
165
+ .hidden {
166
+ display: none;
167
+ }
168
+
169
+ .instructions {
170
+ background: #fff3cd;
171
+ padding: 15px;
172
+ border-radius: 10px;
173
+ margin-bottom: 20px;
174
+ border: 2px solid #ffc107;
175
+ }
176
+
177
+ .instructions h3 {
178
+ color: #856404;
179
+ margin-bottom: 10px;
180
+ }
181
+
182
+ .instructions p {
183
+ color: #856404;
184
+ line-height: 1.6;
185
+ }
186
+ </style>
187
+ </head>
188
+ <body>
189
+ <div class="game-container">
190
+ <div class="header">
191
+ <h1>🏭 Fraction Factory</h1>
192
+ <p>Solve fraction problems before they fall off the conveyor belt!</p>
193
+ </div>
194
+
195
+ <div id="startScreen" class="start-screen">
196
+ <div class="instructions">
197
+ <h3>How to Play:</h3>
198
+ <p>📦 Fraction problems move across the conveyor belt<br>
199
+ ⚡ Solve each problem in 5-10 seconds<br>
200
+ ✅ Correct answers keep the boxes moving<br>
201
+ ❌ Wrong answers make boxes fall off<br>
202
+ 🎯 Get as many correct as you can!</p>
203
+ </div>
204
+ <button class="start-btn" onclick="startGame()">Start Factory</button>
205
+ </div>
206
+
207
+ <div id="gameScreen" class="hidden">
208
+ <div class="stats">
209
+ <div class="stat">
210
+ <div class="stat-label">Score</div>
211
+ <div class="stat-value" id="score">0</div>
212
+ </div>
213
+ <div class="stat">
214
+ <div class="stat-label">Streak</div>
215
+ <div class="stat-value" id="streak">0</div>
216
+ </div>
217
+ <div class="stat">
218
+ <div class="stat-label">Lives</div>
219
+ <div class="stat-value" id="lives">❤️❤️❤️</div>
220
+ </div>
221
+ </div>
222
+
223
+ <canvas id="gameCanvas" class="game-canvas" width="800" height="300"></canvas>
224
+
225
+ <div class="controls" id="controls">
226
+ <!-- Answer buttons will be added dynamically -->
227
+ </div>
228
+
229
+ <div class="feedback" id="feedback"></div>
230
+ </div>
231
+
232
+ <div id="gameOverScreen" class="game-over-screen hidden">
233
+ <h2 style="color: #667eea; font-size: 2.5em; margin-bottom: 20px;">Factory Closed!</h2>
234
+ <p style="font-size: 1.3em; margin-bottom: 10px;">Final Score: <span id="finalScore" style="color: #667eea; font-weight: bold;">0</span></p>
235
+ <p style="font-size: 1.3em; margin-bottom: 30px;">Correct Answers: <span id="correctCount" style="color: #4ade80; font-weight: bold;">0</span></p>
236
+ <button class="restart-btn" onclick="restartGame()">Play Again</button>
237
+ </div>
238
+ </div>
239
+
240
+ <script>
241
+ // Game state
242
+ let gameState = {
243
+ score: 0,
244
+ streak: 0,
245
+ lives: 3,
246
+ currentProblem: null,
247
+ boxPosition: 0,
248
+ isMoving: false,
249
+ correctAnswers: 0,
250
+ totalAnswers: 0
251
+ };
252
+
253
+ // JSON-driven problems (this would normally be loaded from a file)
254
+ const problems = [
255
+ { question: "1/2 + 1/4", answer: "3/4", options: ["3/4", "1/4", "2/4", "3/6"] },
256
+ { question: "2/3 + 1/3", answer: "1", options: ["1", "3/6", "2/3", "3/9"] },
257
+ { question: "3/4 - 1/4", answer: "1/2", options: ["1/2", "2/4", "1/4", "2/8"] },
258
+ { question: "1/2 × 1/2", answer: "1/4", options: ["1/4", "1/2", "2/4", "1/8"] },
259
+ { question: "3/5 + 1/5", answer: "4/5", options: ["4/5", "4/10", "2/5", "3/10"] },
260
+ { question: "5/6 - 2/6", answer: "1/2", options: ["1/2", "3/6", "1/3", "2/3"] },
261
+ { question: "1/3 + 1/6", answer: "1/2", options: ["1/2", "2/9", "1/9", "2/6"] },
262
+ { question: "2/5 × 5/2", answer: "1", options: ["1", "10/10", "4/10", "5/5"] },
263
+ { question: "7/8 - 3/8", answer: "1/2", options: ["1/2", "4/8", "4/16", "1/4"] },
264
+ { question: "1/4 + 2/4", answer: "3/4", options: ["3/4", "3/8", "1/2", "2/4"] }
265
+ ];
266
+
267
+ let canvas, ctx;
268
+ let animationId;
269
+
270
+ function startGame() {
271
+ document.getElementById('startScreen').classList.add('hidden');
272
+ document.getElementById('gameScreen').classList.remove('hidden');
273
+
274
+ canvas = document.getElementById('gameCanvas');
275
+ ctx = canvas.getContext('2d');
276
+
277
+ gameState = {
278
+ score: 0,
279
+ streak: 0,
280
+ lives: 3,
281
+ currentProblem: null,
282
+ boxPosition: 0,
283
+ isMoving: false,
284
+ correctAnswers: 0,
285
+ totalAnswers: 0
286
+ };
287
+
288
+ updateStats();
289
+ loadNextProblem();
290
+ }
291
+
292
+ function loadNextProblem() {
293
+ // Pick a random problem
294
+ const problem = problems[Math.floor(Math.random() * problems.length)];
295
+ gameState.currentProblem = problem;
296
+ gameState.boxPosition = 0;
297
+ gameState.isMoving = true;
298
+
299
+ // Shuffle options
300
+ const shuffledOptions = [...problem.options].sort(() => Math.random() - 0.5);
301
+
302
+ // Create answer buttons
303
+ const controls = document.getElementById('controls');
304
+ controls.innerHTML = '';
305
+
306
+ shuffledOptions.forEach(option => {
307
+ const btn = document.createElement('button');
308
+ btn.className = 'answer-btn';
309
+ btn.textContent = option;
310
+ btn.onclick = () => checkAnswer(option, btn);
311
+ controls.appendChild(btn);
312
+ });
313
+
314
+ document.getElementById('feedback').textContent = '';
315
+ document.getElementById('feedback').className = 'feedback';
316
+
317
+ animate();
318
+ }
319
+
320
+ function animate() {
321
+ if (!gameState.isMoving) return;
322
+
323
+ // Clear canvas
324
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
325
+
326
+ // Draw conveyor belt
327
+ ctx.fillStyle = '#666';
328
+ ctx.fillRect(0, 220, canvas.width, 80);
329
+
330
+ // Draw conveyor belt lines
331
+ ctx.strokeStyle = '#fbbf24';
332
+ ctx.lineWidth = 2;
333
+ for (let i = 0; i < canvas.width; i += 40) {
334
+ ctx.beginPath();
335
+ ctx.moveTo(i + (gameState.boxPosition % 40), 260);
336
+ ctx.lineTo(i + 20 + (gameState.boxPosition % 40), 260);
337
+ ctx.stroke();
338
+ }
339
+
340
+ // Draw factory elements
341
+ ctx.fillStyle = '#8b5cf6';
342
+ ctx.fillRect(10, 100, 60, 120);
343
+ ctx.fillStyle = '#6d28d9';
344
+ ctx.fillRect(20, 110, 40, 40);
345
+
346
+ // Draw box with problem
347
+ const boxX = 100 + gameState.boxPosition;
348
+ const boxY = 150;
349
+
350
+ // Box shadow
351
+ ctx.fillStyle = 'rgba(0,0,0,0.2)';
352
+ ctx.fillRect(boxX + 5, boxY + 5, 120, 80);
353
+
354
+ // Box
355
+ ctx.fillStyle = '#fbbf24';
356
+ ctx.fillRect(boxX, boxY, 120, 80);
357
+ ctx.strokeStyle = '#f59e0b';
358
+ ctx.lineWidth = 3;
359
+ ctx.strokeRect(boxX, boxY, 120, 80);
360
+
361
+ // Problem text
362
+ ctx.fillStyle = '#1f2937';
363
+ ctx.font = 'bold 20px Arial';
364
+ ctx.textAlign = 'center';
365
+ ctx.fillText(gameState.currentProblem.question, boxX + 60, boxY + 45);
366
+ ctx.font = '16px Arial';
367
+ ctx.fillText('= ?', boxX + 60, boxY + 65);
368
+
369
+ // Move box
370
+ gameState.boxPosition += 1.5;
371
+
372
+ // Check if box fell off
373
+ if (gameState.boxPosition > canvas.width - 100) {
374
+ handleTimeout();
375
+ return;
376
+ }
377
+
378
+ animationId = requestAnimationFrame(animate);
379
+ }
380
+
381
+ function checkAnswer(selected, btn) {
382
+ if (!gameState.isMoving) return;
383
+
384
+ gameState.isMoving = false;
385
+ cancelAnimationFrame(animationId);
386
+ gameState.totalAnswers++;
387
+
388
+ const feedback = document.getElementById('feedback');
389
+ const allBtns = document.querySelectorAll('.answer-btn');
390
+
391
+ if (selected === gameState.currentProblem.answer) {
392
+ // Correct answer
393
+ gameState.score += 10 + (gameState.streak * 5);
394
+ gameState.streak++;
395
+ gameState.correctAnswers++;
396
+
397
+ btn.classList.add('correct');
398
+ feedback.textContent = '✓ Correct! Great job!';
399
+ feedback.className = 'feedback correct';
400
+
401
+ allBtns.forEach(b => b.disabled = true);
402
+
403
+ setTimeout(() => {
404
+ loadNextProblem();
405
+ }, 1500);
406
+
407
+ } else {
408
+ // Wrong answer
409
+ gameState.streak = 0;
410
+ gameState.lives--;
411
+
412
+ btn.classList.add('wrong');
413
+ feedback.textContent = `✗ Not quite! The answer was ${gameState.currentProblem.answer}`;
414
+ feedback.className = 'feedback wrong';
415
+
416
+ // Show correct answer
417
+ allBtns.forEach(b => {
418
+ if (b.textContent === gameState.currentProblem.answer) {
419
+ b.classList.add('correct');
420
+ }
421
+ b.disabled = true;
422
+ });
423
+
424
+ if (gameState.lives <= 0) {
425
+ setTimeout(gameOver, 2000);
426
+ } else {
427
+ setTimeout(() => {
428
+ loadNextProblem();
429
+ }, 2000);
430
+ }
431
+ }
432
+
433
+ updateStats();
434
+ }
435
+
436
+ function handleTimeout() {
437
+ gameState.isMoving = false;
438
+ gameState.streak = 0;
439
+ gameState.lives--;
440
+ gameState.totalAnswers++;
441
+
442
+ const feedback = document.getElementById('feedback');
443
+ feedback.textContent = '⏰ Time\'s up! The box fell off!';
444
+ feedback.className = 'feedback wrong';
445
+
446
+ const allBtns = document.querySelectorAll('.answer-btn');
447
+ allBtns.forEach(b => {
448
+ if (b.textContent === gameState.currentProblem.answer) {
449
+ b.classList.add('correct');
450
+ }
451
+ b.disabled = true;
452
+ });
453
+
454
+ updateStats();
455
+
456
+ if (gameState.lives <= 0) {
457
+ setTimeout(gameOver, 2000);
458
+ } else {
459
+ setTimeout(() => {
460
+ loadNextProblem();
461
+ }, 2000);
462
+ }
463
+ }
464
+
465
+ function updateStats() {
466
+ document.getElementById('score').textContent = gameState.score;
467
+ document.getElementById('streak').textContent = gameState.streak;
468
+
469
+ let hearts = '';
470
+ for (let i = 0; i < gameState.lives; i++) {
471
+ hearts += '❤️';
472
+ }
473
+ for (let i = gameState.lives; i < 3; i++) {
474
+ hearts += '🖤';
475
+ }
476
+ document.getElementById('lives').textContent = hearts;
477
+ }
478
+
479
+ function gameOver() {
480
+ document.getElementById('gameScreen').classList.add('hidden');
481
+ document.getElementById('gameOverScreen').classList.remove('hidden');
482
+ document.getElementById('finalScore').textContent = gameState.score;
483
+ document.getElementById('correctCount').textContent =
484
+ `${gameState.correctAnswers} out of ${gameState.totalAnswers}`;
485
+ }
486
+
487
+ function restartGame() {
488
+ document.getElementById('gameOverScreen').classList.add('hidden');
489
+ startGame();
490
+ }
491
+ </script>
492
+ </body>
493
+ </html>