Spaces:
Running
Running
Add 3 files
Browse files- README.md +6 -4
- index.html +510 -19
- prompts.txt +1 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: green
|
| 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: tetris
|
| 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,510 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>Classic Tetris</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
@keyframes flash {
|
| 10 |
+
0% { opacity: 1; }
|
| 11 |
+
50% { opacity: 0.5; }
|
| 12 |
+
100% { opacity: 1; }
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.flash-animation {
|
| 16 |
+
animation: flash 0.3s 2;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.game-container {
|
| 20 |
+
perspective: 1000px;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.tetris-block {
|
| 24 |
+
transition: transform 0.1s;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.tetris-block.placed {
|
| 28 |
+
transition: none;
|
| 29 |
+
}
|
| 30 |
+
</style>
|
| 31 |
+
</head>
|
| 32 |
+
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
|
| 33 |
+
<div class="game-container flex flex-col md:flex-row items-center gap-8">
|
| 34 |
+
<div class="relative">
|
| 35 |
+
<h1 class="text-3xl font-bold mb-4 text-center">CLASSIC TETRIS</h1>
|
| 36 |
+
<div id="game-board" class="bg-gray-800 border-2 border-gray-700 relative overflow-hidden"
|
| 37 |
+
style="width: 300px; height: 600px;"></div>
|
| 38 |
+
<div id="game-over" class="absolute inset-0 bg-black bg-opacity-70 flex flex-col items-center justify-center hidden">
|
| 39 |
+
<h2 class="text-3xl font-bold text-red-500 mb-4">GAME OVER</h2>
|
| 40 |
+
<button id="restart-btn" class="bg-blue-600 hover:bg-blue-700 px-6 py-2 rounded font-bold">
|
| 41 |
+
PLAY AGAIN
|
| 42 |
+
</button>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="flex flex-col gap-6">
|
| 47 |
+
<div class="bg-gray-800 p-4 rounded-lg">
|
| 48 |
+
<h2 class="text-xl font-bold mb-2">NEXT PIECE</h2>
|
| 49 |
+
<div id="next-piece" class="bg-gray-700 p-2 rounded" style="width: 120px; height: 120px;"></div>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
+
<div class="bg-gray-800 p-4 rounded-lg">
|
| 53 |
+
<h2 class="text-xl font-bold mb-2">STATS</h2>
|
| 54 |
+
<div class="grid grid-cols-2 gap-4">
|
| 55 |
+
<div>
|
| 56 |
+
<p class="text-gray-400">Score</p>
|
| 57 |
+
<p id="score" class="text-2xl font-bold">0</p>
|
| 58 |
+
</div>
|
| 59 |
+
<div>
|
| 60 |
+
<p class="text-gray-400">Level</p>
|
| 61 |
+
<p id="level" class="text-2xl font-bold">1</p>
|
| 62 |
+
</div>
|
| 63 |
+
<div>
|
| 64 |
+
<p class="text-gray-400">Lines</p>
|
| 65 |
+
<p id="lines" class="text-2xl font-bold">0</p>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</div>
|
| 69 |
+
|
| 70 |
+
<div class="bg-gray-800 p-4 rounded-lg">
|
| 71 |
+
<h2 class="text-xl font-bold mb-2">CONTROLS</h2>
|
| 72 |
+
<div class="grid grid-cols-2 gap-2 text-sm">
|
| 73 |
+
<div class="bg-gray-700 p-2 rounded">← → Move</div>
|
| 74 |
+
<div class="bg-gray-700 p-2 rounded">↑ Rotate</div>
|
| 75 |
+
<div class="bg-gray-700 p-2 rounded">↓ Drop</div>
|
| 76 |
+
<div class="bg-gray-700 p-2 rounded">Space Hard Drop</div>
|
| 77 |
+
<div class="bg-gray-700 p-2 rounded col-span-2">P Pause</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
<button id="start-btn" class="bg-green-600 hover:bg-green-700 px-6 py-3 rounded-lg font-bold text-lg">
|
| 82 |
+
START GAME
|
| 83 |
+
</button>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<script>
|
| 88 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 89 |
+
// Game constants
|
| 90 |
+
const COLS = 10;
|
| 91 |
+
const ROWS = 20;
|
| 92 |
+
const BLOCK_SIZE = 30;
|
| 93 |
+
const COLORS = [
|
| 94 |
+
null,
|
| 95 |
+
'#FF0D72', // I
|
| 96 |
+
'#0DC2FF', // J
|
| 97 |
+
'#0DFF72', // L
|
| 98 |
+
'#F538FF', // O
|
| 99 |
+
'#FF8E0D', // S
|
| 100 |
+
'#FFE138', // T
|
| 101 |
+
'#3877FF' // Z
|
| 102 |
+
];
|
| 103 |
+
|
| 104 |
+
// Game variables
|
| 105 |
+
let board = createBoard();
|
| 106 |
+
let piece = null;
|
| 107 |
+
let nextPiece = null;
|
| 108 |
+
let score = 0;
|
| 109 |
+
let lines = 0;
|
| 110 |
+
let level = 1;
|
| 111 |
+
let gameOver = false;
|
| 112 |
+
let isPaused = false;
|
| 113 |
+
let dropInterval = null;
|
| 114 |
+
let dropSpeed = 1000; // Initial speed (ms)
|
| 115 |
+
|
| 116 |
+
// DOM elements
|
| 117 |
+
const gameBoard = document.getElementById('game-board');
|
| 118 |
+
const nextPieceDisplay = document.getElementById('next-piece');
|
| 119 |
+
const scoreDisplay = document.getElementById('score');
|
| 120 |
+
const levelDisplay = document.getElementById('level');
|
| 121 |
+
const linesDisplay = document.getElementById('lines');
|
| 122 |
+
const gameOverDisplay = document.getElementById('game-over');
|
| 123 |
+
const startBtn = document.getElementById('start-btn');
|
| 124 |
+
const restartBtn = document.getElementById('restart-btn');
|
| 125 |
+
|
| 126 |
+
// Initialize the game board
|
| 127 |
+
function createBoard() {
|
| 128 |
+
return Array.from(Array(ROWS), () => Array(COLS).fill(0));
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// Piece shapes
|
| 132 |
+
const PIECES = [
|
| 133 |
+
null,
|
| 134 |
+
// I
|
| 135 |
+
[
|
| 136 |
+
[0, 0, 0, 0],
|
| 137 |
+
[1, 1, 1, 1],
|
| 138 |
+
[0, 0, 0, 0],
|
| 139 |
+
[0, 0, 0, 0]
|
| 140 |
+
],
|
| 141 |
+
// J
|
| 142 |
+
[
|
| 143 |
+
[2, 0, 0],
|
| 144 |
+
[2, 2, 2],
|
| 145 |
+
[0, 0, 0]
|
| 146 |
+
],
|
| 147 |
+
// L
|
| 148 |
+
[
|
| 149 |
+
[0, 0, 3],
|
| 150 |
+
[3, 3, 3],
|
| 151 |
+
[0, 0, 0]
|
| 152 |
+
],
|
| 153 |
+
// O
|
| 154 |
+
[
|
| 155 |
+
[4, 4],
|
| 156 |
+
[4, 4]
|
| 157 |
+
],
|
| 158 |
+
// S
|
| 159 |
+
[
|
| 160 |
+
[0, 5, 5],
|
| 161 |
+
[5, 5, 0],
|
| 162 |
+
[0, 0, 0]
|
| 163 |
+
],
|
| 164 |
+
// T
|
| 165 |
+
[
|
| 166 |
+
[0, 6, 0],
|
| 167 |
+
[6, 6, 6],
|
| 168 |
+
[0, 0, 0]
|
| 169 |
+
],
|
| 170 |
+
// Z
|
| 171 |
+
[
|
| 172 |
+
[7, 7, 0],
|
| 173 |
+
[0, 7, 7],
|
| 174 |
+
[0, 0, 0]
|
| 175 |
+
]
|
| 176 |
+
];
|
| 177 |
+
|
| 178 |
+
// Create a new piece
|
| 179 |
+
function createPiece(type) {
|
| 180 |
+
return {
|
| 181 |
+
position: {x: Math.floor(COLS / 2) - 2, y: 0},
|
| 182 |
+
shape: PIECES[type],
|
| 183 |
+
type: type
|
| 184 |
+
};
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
// Draw the game board
|
| 188 |
+
function draw() {
|
| 189 |
+
// Clear the board
|
| 190 |
+
gameBoard.innerHTML = '';
|
| 191 |
+
|
| 192 |
+
// Draw the current piece
|
| 193 |
+
if (piece) {
|
| 194 |
+
piece.shape.forEach((row, y) => {
|
| 195 |
+
row.forEach((value, x) => {
|
| 196 |
+
if (value) {
|
| 197 |
+
const block = document.createElement('div');
|
| 198 |
+
block.className = `tetris-block absolute w-[30px] h-[30px] border border-gray-900`;
|
| 199 |
+
block.style.backgroundColor = COLORS[piece.type];
|
| 200 |
+
block.style.left = `${(piece.position.x + x) * BLOCK_SIZE}px`;
|
| 201 |
+
block.style.top = `${(piece.position.y + y) * BLOCK_SIZE}px`;
|
| 202 |
+
gameBoard.appendChild(block);
|
| 203 |
+
}
|
| 204 |
+
});
|
| 205 |
+
});
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Draw the placed pieces
|
| 209 |
+
board.forEach((row, y) => {
|
| 210 |
+
row.forEach((value, x) => {
|
| 211 |
+
if (value) {
|
| 212 |
+
const block = document.createElement('div');
|
| 213 |
+
block.className = `tetris-block placed absolute w-[30px] h-[30px] border border-gray-900`;
|
| 214 |
+
block.style.backgroundColor = COLORS[value];
|
| 215 |
+
block.style.left = `${x * BLOCK_SIZE}px`;
|
| 216 |
+
block.style.top = `${y * BLOCK_SIZE}px`;
|
| 217 |
+
gameBoard.appendChild(block);
|
| 218 |
+
}
|
| 219 |
+
});
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
// Draw the next piece
|
| 223 |
+
nextPieceDisplay.innerHTML = '';
|
| 224 |
+
if (nextPiece) {
|
| 225 |
+
const offsetX = (4 - nextPiece.shape[0].length) * 15;
|
| 226 |
+
const offsetY = (4 - nextPiece.shape.length) * 15;
|
| 227 |
+
|
| 228 |
+
nextPiece.shape.forEach((row, y) => {
|
| 229 |
+
row.forEach((value, x) => {
|
| 230 |
+
if (value) {
|
| 231 |
+
const block = document.createElement('div');
|
| 232 |
+
block.className = `tetris-block absolute w-[30px] h-[30px] border border-gray-900`;
|
| 233 |
+
block.style.backgroundColor = COLORS[nextPiece.type];
|
| 234 |
+
block.style.left = `${x * BLOCK_SIZE + offsetX}px`;
|
| 235 |
+
block.style.top = `${y * BLOCK_SIZE + offsetY}px`;
|
| 236 |
+
nextPieceDisplay.appendChild(block);
|
| 237 |
+
}
|
| 238 |
+
});
|
| 239 |
+
});
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
// Move the piece
|
| 244 |
+
function movePiece(direction) {
|
| 245 |
+
if (gameOver || isPaused) return;
|
| 246 |
+
|
| 247 |
+
switch (direction) {
|
| 248 |
+
case 'left':
|
| 249 |
+
piece.position.x--;
|
| 250 |
+
if (isCollision()) {
|
| 251 |
+
piece.position.x++;
|
| 252 |
+
}
|
| 253 |
+
break;
|
| 254 |
+
case 'right':
|
| 255 |
+
piece.position.x++;
|
| 256 |
+
if (isCollision()) {
|
| 257 |
+
piece.position.x--;
|
| 258 |
+
}
|
| 259 |
+
break;
|
| 260 |
+
case 'down':
|
| 261 |
+
piece.position.y++;
|
| 262 |
+
if (isCollision()) {
|
| 263 |
+
piece.position.y--;
|
| 264 |
+
placePiece();
|
| 265 |
+
clearLines();
|
| 266 |
+
if (!gameOver) {
|
| 267 |
+
spawnPiece();
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
break;
|
| 271 |
+
}
|
| 272 |
+
draw();
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
// Rotate the piece
|
| 276 |
+
function rotatePiece() {
|
| 277 |
+
if (gameOver || isPaused) return;
|
| 278 |
+
|
| 279 |
+
const originalShape = piece.shape;
|
| 280 |
+
// Transpose the matrix
|
| 281 |
+
const rows = piece.shape.length;
|
| 282 |
+
const cols = piece.shape[0].length;
|
| 283 |
+
const newShape = Array(cols).fill().map(() => Array(rows).fill(0));
|
| 284 |
+
|
| 285 |
+
for (let y = 0; y < rows; y++) {
|
| 286 |
+
for (let x = 0; x < cols; x++) {
|
| 287 |
+
newShape[x][rows - 1 - y] = piece.shape[y][x];
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
piece.shape = newShape;
|
| 292 |
+
|
| 293 |
+
// If rotation causes collision, try wall kicks
|
| 294 |
+
if (isCollision()) {
|
| 295 |
+
// Try moving left
|
| 296 |
+
piece.position.x--;
|
| 297 |
+
if (isCollision()) {
|
| 298 |
+
piece.position.x += 2; // Try moving right
|
| 299 |
+
if (isCollision()) {
|
| 300 |
+
piece.position.x--; // Revert
|
| 301 |
+
piece.shape = originalShape; // Revert rotation
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
draw();
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// Check for collisions
|
| 310 |
+
function isCollision() {
|
| 311 |
+
for (let y = 0; y < piece.shape.length; y++) {
|
| 312 |
+
for (let x = 0; x < piece.shape[y].length; x++) {
|
| 313 |
+
if (piece.shape[y][x] !== 0) {
|
| 314 |
+
const boardX = piece.position.x + x;
|
| 315 |
+
const boardY = piece.position.y + y;
|
| 316 |
+
|
| 317 |
+
if (
|
| 318 |
+
boardX < 0 ||
|
| 319 |
+
boardX >= COLS ||
|
| 320 |
+
boardY >= ROWS ||
|
| 321 |
+
(boardY >= 0 && board[boardY][boardX])
|
| 322 |
+
) {
|
| 323 |
+
return true;
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
}
|
| 327 |
+
}
|
| 328 |
+
return false;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// Place the piece on the board
|
| 332 |
+
function placePiece() {
|
| 333 |
+
piece.shape.forEach((row, y) => {
|
| 334 |
+
row.forEach((value, x) => {
|
| 335 |
+
if (value) {
|
| 336 |
+
const boardY = piece.position.y + y;
|
| 337 |
+
const boardX = piece.position.x + x;
|
| 338 |
+
if (boardY >= 0) { // Only place if within visible area
|
| 339 |
+
board[boardY][boardX] = piece.type;
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
});
|
| 343 |
+
});
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
// Spawn a new piece
|
| 347 |
+
function spawnPiece() {
|
| 348 |
+
piece = nextPiece || createPiece(Math.floor(Math.random() * 7) + 1);
|
| 349 |
+
nextPiece = createPiece(Math.floor(Math.random() * 7) + 1);
|
| 350 |
+
|
| 351 |
+
// Check for game over
|
| 352 |
+
if (isCollision()) {
|
| 353 |
+
gameOver = true;
|
| 354 |
+
clearInterval(dropInterval);
|
| 355 |
+
gameOverDisplay.classList.remove('hidden');
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// Clear completed lines
|
| 360 |
+
function clearLines() {
|
| 361 |
+
let linesCleared = 0;
|
| 362 |
+
|
| 363 |
+
for (let y = ROWS - 1; y >= 0; y--) {
|
| 364 |
+
if (board[y].every(cell => cell !== 0)) {
|
| 365 |
+
// Remove the line
|
| 366 |
+
board.splice(y, 1);
|
| 367 |
+
// Add a new empty line at the top
|
| 368 |
+
board.unshift(Array(COLS).fill(0));
|
| 369 |
+
linesCleared++;
|
| 370 |
+
y++; // Check the same row again (now with new content)
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
if (linesCleared > 0) {
|
| 375 |
+
// Update score
|
| 376 |
+
const points = [0, 40, 100, 300, 1200][linesCleared] * level;
|
| 377 |
+
score += points;
|
| 378 |
+
lines += linesCleared;
|
| 379 |
+
|
| 380 |
+
// Update level every 10 lines
|
| 381 |
+
level = Math.floor(lines / 10) + 1;
|
| 382 |
+
|
| 383 |
+
// Increase speed
|
| 384 |
+
dropSpeed = Math.max(100, 1000 - (level - 1) * 50);
|
| 385 |
+
|
| 386 |
+
// Update displays
|
| 387 |
+
scoreDisplay.textContent = score;
|
| 388 |
+
levelDisplay.textContent = level;
|
| 389 |
+
linesDisplay.textContent = lines;
|
| 390 |
+
|
| 391 |
+
// Flash animation
|
| 392 |
+
gameBoard.classList.add('flash-animation');
|
| 393 |
+
setTimeout(() => {
|
| 394 |
+
gameBoard.classList.remove('flash-animation');
|
| 395 |
+
}, 600);
|
| 396 |
+
|
| 397 |
+
// Restart the drop interval with new speed
|
| 398 |
+
clearInterval(dropInterval);
|
| 399 |
+
dropInterval = setInterval(() => movePiece('down'), dropSpeed);
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// Hard drop - instantly place the piece
|
| 404 |
+
function hardDrop() {
|
| 405 |
+
if (gameOver || isPaused) return;
|
| 406 |
+
|
| 407 |
+
while (!isCollision()) {
|
| 408 |
+
piece.position.y++;
|
| 409 |
+
}
|
| 410 |
+
piece.position.y--;
|
| 411 |
+
placePiece();
|
| 412 |
+
clearLines();
|
| 413 |
+
if (!gameOver) {
|
| 414 |
+
spawnPiece();
|
| 415 |
+
}
|
| 416 |
+
draw();
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Pause the game
|
| 420 |
+
function togglePause() {
|
| 421 |
+
if (gameOver) return;
|
| 422 |
+
|
| 423 |
+
isPaused = !isPaused;
|
| 424 |
+
|
| 425 |
+
if (isPaused) {
|
| 426 |
+
clearInterval(dropInterval);
|
| 427 |
+
document.getElementById('game-board').style.opacity = '0.5';
|
| 428 |
+
} else {
|
| 429 |
+
dropInterval = setInterval(() => movePiece('down'), dropSpeed);
|
| 430 |
+
document.getElementById('game-board').style.opacity = '1';
|
| 431 |
+
}
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
// Start the game
|
| 435 |
+
function startGame() {
|
| 436 |
+
// Reset game state
|
| 437 |
+
board = createBoard();
|
| 438 |
+
score = 0;
|
| 439 |
+
lines = 0;
|
| 440 |
+
level = 1;
|
| 441 |
+
gameOver = false;
|
| 442 |
+
isPaused = false;
|
| 443 |
+
|
| 444 |
+
// Update displays
|
| 445 |
+
scoreDisplay.textContent = score;
|
| 446 |
+
levelDisplay.textContent = level;
|
| 447 |
+
linesDisplay.textContent = lines;
|
| 448 |
+
|
| 449 |
+
// Hide game over screen
|
| 450 |
+
gameOverDisplay.classList.add('hidden');
|
| 451 |
+
|
| 452 |
+
// Create initial pieces
|
| 453 |
+
nextPiece = createPiece(Math.floor(Math.random() * 7) + 1);
|
| 454 |
+
spawnPiece();
|
| 455 |
+
|
| 456 |
+
// Start the drop interval
|
| 457 |
+
dropSpeed = 1000;
|
| 458 |
+
clearInterval(dropInterval);
|
| 459 |
+
dropInterval = setInterval(() => movePiece('down'), dropSpeed);
|
| 460 |
+
|
| 461 |
+
// Draw the initial state
|
| 462 |
+
draw();
|
| 463 |
+
|
| 464 |
+
// Focus the game board for keyboard controls
|
| 465 |
+
gameBoard.focus();
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
// Event listeners
|
| 469 |
+
document.addEventListener('keydown', (e) => {
|
| 470 |
+
if (gameOver && e.key === 'Enter') {
|
| 471 |
+
startGame();
|
| 472 |
+
return;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
switch (e.key) {
|
| 476 |
+
case 'ArrowLeft':
|
| 477 |
+
movePiece('left');
|
| 478 |
+
break;
|
| 479 |
+
case 'ArrowRight':
|
| 480 |
+
movePiece('right');
|
| 481 |
+
break;
|
| 482 |
+
case 'ArrowDown':
|
| 483 |
+
movePiece('down');
|
| 484 |
+
break;
|
| 485 |
+
case 'ArrowUp':
|
| 486 |
+
rotatePiece();
|
| 487 |
+
break;
|
| 488 |
+
case ' ':
|
| 489 |
+
hardDrop();
|
| 490 |
+
break;
|
| 491 |
+
case 'p':
|
| 492 |
+
case 'P':
|
| 493 |
+
togglePause();
|
| 494 |
+
break;
|
| 495 |
+
}
|
| 496 |
+
});
|
| 497 |
+
|
| 498 |
+
startBtn.addEventListener('click', startGame);
|
| 499 |
+
restartBtn.addEventListener('click', startGame);
|
| 500 |
+
|
| 501 |
+
// Make the game board focusable
|
| 502 |
+
gameBoard.setAttribute('tabindex', '0');
|
| 503 |
+
gameBoard.focus();
|
| 504 |
+
|
| 505 |
+
// Initial draw
|
| 506 |
+
draw();
|
| 507 |
+
});
|
| 508 |
+
</script>
|
| 509 |
+
<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=faltimiras33/tetris" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 510 |
+
</html>
|
prompts.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
create a tetris game with solid blocks as the classic game
|