Mohabedalgani commited on
Commit
252bfbe
·
verified ·
1 Parent(s): dda2f09

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. index.html +441 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Zaido
3
- emoji: 🐠
4
  colorFrom: red
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: zaido
3
+ emoji: 🐳
4
  colorFrom: red
5
+ colorTo: green
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,441 @@
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>Brick Attacker Game</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ #gameCanvas {
10
+ background-color: #1a202c;
11
+ border-radius: 8px;
12
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
13
+ }
14
+
15
+ .game-container {
16
+ position: relative;
17
+ }
18
+
19
+ .game-overlay {
20
+ position: absolute;
21
+ top: 0;
22
+ left: 0;
23
+ width: 100%;
24
+ height: 100%;
25
+ display: flex;
26
+ flex-direction: column;
27
+ justify-content: center;
28
+ align-items: center;
29
+ background-color: rgba(0, 0, 0, 0.7);
30
+ color: white;
31
+ border-radius: 8px;
32
+ }
33
+
34
+ .hidden {
35
+ display: none;
36
+ }
37
+
38
+ .brick {
39
+ border-radius: 2px;
40
+ }
41
+
42
+ .heart-icon {
43
+ color: #f56565;
44
+ }
45
+ </style>
46
+ </head>
47
+ <body class="bg-gray-900 min-h-screen flex flex-col items-center justify-center p-4">
48
+ <div class="max-w-4xl w-full">
49
+ <h1 class="text-3xl font-bold text-center text-white mb-6">Brick Attacker</h1>
50
+
51
+ <div class="flex justify-between items-center mb-4">
52
+ <div class="flex items-center space-x-2">
53
+ <span class="text-white font-semibold">Score:</span>
54
+ <span id="score" class="text-yellow-300 font-bold text-xl">0</span>
55
+ </div>
56
+ <div class="flex items-center space-x-2">
57
+ <span class="text-white font-semibold">Lives:</span>
58
+ <div id="lives" class="flex space-x-1">
59
+ <!-- Hearts will be added here by JavaScript -->
60
+ </div>
61
+ </div>
62
+ </div>
63
+
64
+ <div class="game-container relative">
65
+ <canvas id="gameCanvas" width="800" height="500"></canvas>
66
+
67
+ <div id="startScreen" class="game-overlay">
68
+ <h2 class="text-4xl font-bold mb-6 text-yellow-300">Brick Attacker</h2>
69
+ <p class="text-xl mb-8 text-center max-w-md">Use your mouse or arrow keys to move the paddle.<br>Break all bricks to win!</p>
70
+ <button id="startButton" class="bg-green-500 hover:bg-green-600 text-white font-bold py-3 px-8 rounded-full text-xl transition duration-200 transform hover:scale-105">
71
+ Start Game
72
+ </button>
73
+ </div>
74
+
75
+ <div id="gameOverScreen" class="game-overlay hidden">
76
+ <h2 class="text-4xl font-bold mb-4 text-red-500">Game Over</h2>
77
+ <p class="text-2xl mb-2">Your score: <span id="finalScore" class="text-yellow-300">0</span></p>
78
+ <button id="restartButton" class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-6 rounded-full text-lg mt-6 transition duration-200 transform hover:scale-105">
79
+ Play Again
80
+ </button>
81
+ </div>
82
+
83
+ <div id="winScreen" class="game-overlay hidden">
84
+ <h2 class="text-4xl font-bold mb-4 text-green-400">You Win!</h2>
85
+ <p class="text-2xl mb-2">Your score: <span id="winScore" class="text-yellow-300">0</span></p>
86
+ <button id="winRestartButton" class="bg-purple-500 hover:bg-purple-600 text-white font-bold py-2 px-6 rounded-full text-lg mt-6 transition duration-200 transform hover:scale-105">
87
+ Play Again
88
+ </button>
89
+ </div>
90
+ </div>
91
+
92
+ <div class="mt-6 text-center text-gray-400">
93
+ <p>Controls: Mouse movement or Left/Right arrow keys</p>
94
+ </div>
95
+ </div>
96
+
97
+ <script>
98
+ document.addEventListener('DOMContentLoaded', () => {
99
+ // Game elements
100
+ const canvas = document.getElementById('gameCanvas');
101
+ const ctx = canvas.getContext('2d');
102
+ const scoreElement = document.getElementById('score');
103
+ const livesElement = document.getElementById('lives');
104
+ const startScreen = document.getElementById('startScreen');
105
+ const gameOverScreen = document.getElementById('gameOverScreen');
106
+ const winScreen = document.getElementById('winScreen');
107
+ const startButton = document.getElementById('startButton');
108
+ const restartButton = document.getElementById('restartButton');
109
+ const winRestartButton = document.getElementById('winRestartButton');
110
+ const finalScoreElement = document.getElementById('finalScore');
111
+ const winScoreElement = document.getElementById('winScore');
112
+
113
+ // Game variables
114
+ let score = 0;
115
+ let lives = 3;
116
+ let gameRunning = false;
117
+ let animationId;
118
+
119
+ // Game objects
120
+ const ball = {
121
+ x: canvas.width / 2,
122
+ y: canvas.height - 30,
123
+ radius: 10,
124
+ dx: 4,
125
+ dy: -4,
126
+ color: '#f56565'
127
+ };
128
+
129
+ const paddle = {
130
+ width: 100,
131
+ height: 15,
132
+ x: canvas.width / 2 - 50,
133
+ speed: 8,
134
+ color: '#4299e1'
135
+ };
136
+
137
+ const brick = {
138
+ rowCount: 5,
139
+ columnCount: 10,
140
+ width: 75,
141
+ height: 20,
142
+ padding: 10,
143
+ offsetTop: 50,
144
+ offsetLeft: 30,
145
+ colors: ['#48bb78', '#f6ad55', '#9f7aea', '#f687b3', '#4fd1c5']
146
+ };
147
+
148
+ let bricks = [];
149
+
150
+ // Initialize bricks
151
+ function initBricks() {
152
+ bricks = [];
153
+ for (let c = 0; c < brick.columnCount; c++) {
154
+ bricks[c] = [];
155
+ for (let r = 0; r < brick.rowCount; r++) {
156
+ bricks[c][r] = { x: 0, y: 0, status: 1, color: brick.colors[r % brick.colors.length] };
157
+ }
158
+ }
159
+ }
160
+
161
+ // Draw ball
162
+ function drawBall() {
163
+ ctx.beginPath();
164
+ ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
165
+ ctx.fillStyle = ball.color;
166
+ ctx.fill();
167
+ ctx.closePath();
168
+ }
169
+
170
+ // Draw paddle
171
+ function drawPaddle() {
172
+ ctx.beginPath();
173
+ ctx.roundRect(paddle.x, canvas.height - paddle.height - 10, paddle.width, paddle.height, 8);
174
+ ctx.fillStyle = paddle.color;
175
+ ctx.fill();
176
+ ctx.closePath();
177
+ }
178
+
179
+ // Draw bricks
180
+ function drawBricks() {
181
+ for (let c = 0; c < brick.columnCount; c++) {
182
+ for (let r = 0; r < brick.rowCount; r++) {
183
+ if (bricks[c][r].status === 1) {
184
+ const brickX = c * (brick.width + brick.padding) + brick.offsetLeft;
185
+ const brickY = r * (brick.height + brick.padding) + brick.offsetTop;
186
+ bricks[c][r].x = brickX;
187
+ bricks[c][r].y = brickY;
188
+
189
+ ctx.beginPath();
190
+ ctx.roundRect(brickX, brickY, brick.width, brick.height, 2);
191
+ ctx.fillStyle = bricks[c][r].color;
192
+ ctx.fill();
193
+ ctx.closePath();
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
+ // Collision detection
200
+ function collisionDetection() {
201
+ for (let c = 0; c < brick.columnCount; c++) {
202
+ for (let r = 0; r < brick.rowCount; r++) {
203
+ const b = bricks[c][r];
204
+ if (b.status === 1) {
205
+ if (
206
+ ball.x + ball.radius > b.x &&
207
+ ball.x - ball.radius < b.x + brick.width &&
208
+ ball.y + ball.radius > b.y &&
209
+ ball.y - ball.radius < b.y + brick.height
210
+ ) {
211
+ ball.dy = -ball.dy;
212
+ b.status = 0;
213
+ score += 10;
214
+ scoreElement.textContent = score;
215
+
216
+ // Check if all bricks are broken
217
+ if (checkWin()) {
218
+ gameWin();
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+
226
+ // Check if all bricks are broken
227
+ function checkWin() {
228
+ for (let c = 0; c < brick.columnCount; c++) {
229
+ for (let r = 0; r < brick.rowCount; r++) {
230
+ if (bricks[c][r].status === 1) {
231
+ return false;
232
+ }
233
+ }
234
+ }
235
+ return true;
236
+ }
237
+
238
+ // Update lives display
239
+ function updateLivesDisplay() {
240
+ livesElement.innerHTML = '';
241
+ for (let i = 0; i < lives; i++) {
242
+ livesElement.innerHTML += `
243
+ <svg class="heart-icon w-6 h-6" fill="currentColor" viewBox="0 0 20 20">
244
+ <path fill-rule="evenodd" d="M3.172 5.172a4 4 0 015.656 0L10 6.343l1.172-1.171a4 4 0 115.656 5.656L10 17.657l-6.828-6.829a4 4 0 010-5.656z" clip-rule="evenodd"></path>
245
+ </svg>
246
+ `;
247
+ }
248
+ }
249
+
250
+ // Main game loop
251
+ function draw() {
252
+ // Clear canvas
253
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
254
+
255
+ // Draw game objects
256
+ drawBricks();
257
+ drawBall();
258
+ drawPaddle();
259
+
260
+ // Collision detection
261
+ collisionDetection();
262
+
263
+ // Wall collision (left/right)
264
+ if (ball.x + ball.dx > canvas.width - ball.radius || ball.x + ball.dx < ball.radius) {
265
+ ball.dx = -ball.dx;
266
+ }
267
+
268
+ // Wall collision (top)
269
+ if (ball.y + ball.dy < ball.radius) {
270
+ ball.dy = -ball.dy;
271
+ }
272
+ // Paddle collision
273
+ else if (
274
+ ball.y + ball.dy > canvas.height - ball.radius - paddle.height - 10 &&
275
+ ball.x > paddle.x &&
276
+ ball.x < paddle.x + paddle.width
277
+ ) {
278
+ // Calculate bounce angle based on where ball hits paddle
279
+ const hitPosition = (ball.x - (paddle.x + paddle.width / 2)) / (paddle.width / 2);
280
+ const angle = hitPosition * Math.PI / 3; // Max 60 degrees
281
+
282
+ ball.dx = 5 * Math.sin(angle);
283
+ ball.dy = -Math.abs(5 * Math.cos(angle));
284
+ }
285
+ // Bottom wall collision (lose life)
286
+ else if (ball.y + ball.dy > canvas.height - ball.radius) {
287
+ lives--;
288
+ updateLivesDisplay();
289
+
290
+ if (lives <= 0) {
291
+ gameOver();
292
+ } else {
293
+ // Reset ball and paddle
294
+ ball.x = canvas.width / 2;
295
+ ball.y = canvas.height - 30;
296
+ ball.dx = 4 * (Math.random() > 0.5 ? 1 : -1);
297
+ ball.dy = -4;
298
+ paddle.x = canvas.width / 2 - paddle.width / 2;
299
+ }
300
+ }
301
+
302
+ // Move ball
303
+ ball.x += ball.dx;
304
+ ball.y += ball.dy;
305
+
306
+ // Continue animation
307
+ if (gameRunning) {
308
+ animationId = requestAnimationFrame(draw);
309
+ }
310
+ }
311
+
312
+ // Keyboard controls
313
+ let rightPressed = false;
314
+ let leftPressed = false;
315
+
316
+ document.addEventListener('keydown', (e) => {
317
+ if (e.key === 'Right' || e.key === 'ArrowRight') {
318
+ rightPressed = true;
319
+ } else if (e.key === 'Left' || e.key === 'ArrowLeft') {
320
+ leftPressed = true;
321
+ }
322
+ });
323
+
324
+ document.addEventListener('keyup', (e) => {
325
+ if (e.key === 'Right' || e.key === 'ArrowRight') {
326
+ rightPressed = false;
327
+ } else if (e.key === 'Left' || e.key === 'ArrowLeft') {
328
+ leftPressed = false;
329
+ }
330
+ });
331
+
332
+ // Mouse controls
333
+ document.addEventListener('mousemove', (e) => {
334
+ if (!gameRunning) return;
335
+
336
+ const relativeX = e.clientX - canvas.offsetLeft;
337
+ if (relativeX > paddle.width / 2 && relativeX < canvas.width - paddle.width / 2) {
338
+ paddle.x = relativeX - paddle.width / 2;
339
+ }
340
+ });
341
+
342
+ // Touch controls for mobile
343
+ document.addEventListener('touchmove', (e) => {
344
+ if (!gameRunning) return;
345
+ e.preventDefault();
346
+
347
+ const touch = e.touches[0];
348
+ const relativeX = touch.clientX - canvas.offsetLeft;
349
+ if (relativeX > paddle.width / 2 && relativeX < canvas.width - paddle.width / 2) {
350
+ paddle.x = relativeX - paddle.width / 2;
351
+ }
352
+ }, { passive: false });
353
+
354
+ // Update paddle position based on keyboard input
355
+ function updatePaddlePosition() {
356
+ if (rightPressed && paddle.x < canvas.width - paddle.width) {
357
+ paddle.x += paddle.speed;
358
+ } else if (leftPressed && paddle.x > 0) {
359
+ paddle.x -= paddle.speed;
360
+ }
361
+ }
362
+
363
+ // Game over
364
+ function gameOver() {
365
+ gameRunning = false;
366
+ cancelAnimationFrame(animationId);
367
+ finalScoreElement.textContent = score;
368
+ gameOverScreen.classList.remove('hidden');
369
+ }
370
+
371
+ // Game win
372
+ function gameWin() {
373
+ gameRunning = false;
374
+ cancelAnimationFrame(animationId);
375
+ winScoreElement.textContent = score;
376
+ winScreen.classList.remove('hidden');
377
+ }
378
+
379
+ // Reset game
380
+ function resetGame() {
381
+ score = 0;
382
+ lives = 3;
383
+ scoreElement.textContent = score;
384
+ updateLivesDisplay();
385
+
386
+ ball.x = canvas.width / 2;
387
+ ball.y = canvas.height - 30;
388
+ ball.dx = 4 * (Math.random() > 0.5 ? 1 : -1);
389
+ ball.dy = -4;
390
+
391
+ paddle.x = canvas.width / 2 - paddle.width / 2;
392
+
393
+ initBricks();
394
+ }
395
+
396
+ // Start game
397
+ function startGame() {
398
+ resetGame();
399
+ startScreen.classList.add('hidden');
400
+ gameOverScreen.classList.add('hidden');
401
+ winScreen.classList.add('hidden');
402
+ gameRunning = true;
403
+ draw();
404
+ }
405
+
406
+ // Event listeners for buttons
407
+ startButton.addEventListener('click', startGame);
408
+ restartButton.addEventListener('click', startGame);
409
+ winRestartButton.addEventListener('click', startGame);
410
+
411
+ // Initialize game
412
+ updateLivesDisplay();
413
+
414
+ // Make canvas responsive
415
+ function resizeCanvas() {
416
+ const container = document.querySelector('.game-container');
417
+ const containerWidth = container.clientWidth;
418
+
419
+ // Maintain aspect ratio (16:10)
420
+ canvas.width = Math.min(800, containerWidth);
421
+ canvas.height = (canvas.width * 5) / 8;
422
+
423
+ // Adjust ball and paddle size based on canvas size
424
+ ball.radius = canvas.width / 80;
425
+ paddle.width = canvas.width / 8;
426
+ paddle.height = canvas.height / 35;
427
+
428
+ // Reset game objects
429
+ if (!gameRunning) {
430
+ ball.x = canvas.width / 2;
431
+ ball.y = canvas.height - 30;
432
+ paddle.x = canvas.width / 2 - paddle.width / 2;
433
+ }
434
+ }
435
+
436
+ window.addEventListener('resize', resizeCanvas);
437
+ resizeCanvas();
438
+ });
439
+ </script>
440
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Mohabedalgani/zaido" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
441
+ </html>