test-space / index.html
fgalopo's picture
Add 2 files
4804c0c verified
Raw History Blame Contribute Delete
19.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emoji Tetris</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
.pulse-emoji {
animation: pulse 1.5s infinite;
}
.game-over {
background-color: rgba(0, 0, 0, 0.8);
}
.cell {
transition: all 0.1s ease;
}
.cell.filled {
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
<div class="text-center mb-6">
<h1 class="text-4xl font-bold mb-2 text-transparent bg-clip-text bg-gradient-to-r from-purple-400 to-pink-600">Emoji Tetris</h1>
<p class="text-gray-300">Use ← → to move, ↑ to rotate, ↓ to drop faster</p>
</div>
<div class="flex flex-col md:flex-row items-center gap-8">
<div class="relative">
<div id="game-board" class="grid grid-cols-10 gap-0 border-4 border-purple-500 rounded-lg bg-gray-800 shadow-lg shadow-purple-500/20"></div>
<div id="game-over" class="game-over absolute inset-0 flex flex-col items-center justify-center hidden rounded-lg">
<h2 class="text-3xl font-bold mb-4 text-red-400">Game Over!</h2>
<p class="text-xl mb-6">Score: <span id="final-score" class="text-yellow-300">0</span></p>
<button id="restart-btn" class="px-6 py-2 bg-purple-600 hover:bg-purple-700 rounded-full font-bold transition-all transform hover:scale-105">
Play Again
</button>
</div>
</div>
<div class="flex flex-col gap-6">
<div class="bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-xl font-semibold mb-3 text-purple-300">Next Piece</h3>
<div id="next-piece" class="grid grid-cols-4 gap-1 w-24 h-24"></div>
</div>
<div class="bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-xl font-semibold mb-3 text-purple-300">Score</h3>
<div class="text-2xl font-bold text-yellow-300" id="score">0</div>
</div>
<div class="bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-xl font-semibold mb-3 text-purple-300">Level</h3>
<div class="text-2xl font-bold text-green-300" id="level">1</div>
</div>
<div class="bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-xl font-semibold mb-3 text-purple-300">Controls</h3>
<div class="grid grid-cols-2 gap-2 text-sm">
<div class="flex items-center gap-2">
<span class="bg-gray-700 px-2 py-1 rounded">↑</span>
<span>Rotate</span>
</div>
<div class="flex items-center gap-2">
<span class="bg-gray-700 px-2 py-1 rounded">↓</span>
<span>Drop</span>
</div>
<div class="flex items-center gap-2">
<span class="bg-gray-700 px-2 py-1 rounded">←</span>
<span>Left</span>
</div>
<div class="flex items-center gap-2">
<span class="bg-gray-700 px-2 py-1 rounded">→</span>
<span>Right</span>
</div>
</div>
</div>
</div>
</div>
<div class="mt-8 text-gray-400 text-sm">
<p>Clear lines by filling rows with emojis. Have fun!</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Game constants
const COLS = 10;
const ROWS = 20;
const BLOCK_SIZE = 30;
const EMOJIS = ['😀', '😂', '😍', '🤩', '😎', '🥳', '🤪', '👻', '🐶', '🦄', '🍕', '🍩', '⚡', '🌈', '🎮'];
const COLORS = [
'bg-red-400', 'bg-blue-400', 'bg-green-400', 'bg-yellow-400',
'bg-purple-400', 'bg-pink-400', 'bg-indigo-400', 'bg-teal-400'
];
// Game variables
let board = Array(ROWS).fill().map(() => Array(COLS).fill(0));
let currentPiece = null;
let nextPiece = null;
let score = 0;
let level = 1;
let gameOver = false;
let dropInterval = null;
let dropSpeed = 1000; // ms
// DOM elements
const gameBoard = document.getElementById('game-board');
const nextPieceDisplay = document.getElementById('next-piece');
const scoreDisplay = document.getElementById('score');
const levelDisplay = document.getElementById('level');
const gameOverDisplay = document.getElementById('game-over');
const finalScoreDisplay = document.getElementById('final-score');
const restartBtn = document.getElementById('restart-btn');
// Initialize game board
function initBoard() {
gameBoard.innerHTML = '';
gameBoard.style.gridTemplateColumns = `repeat(${COLS}, ${BLOCK_SIZE}px)`;
gameBoard.style.width = `${COLS * BLOCK_SIZE}px`;
gameBoard.style.height = `${ROWS * BLOCK_SIZE}px`;
for (let row = 0; row < ROWS; row++) {
for (let col = ��� 0; col < COLS; col++) {
const cell = document.createElement('div');
cell.className = `cell w-[${BLOCK_SIZE}px] h-[${BLOCK_SIZE}px] border border-gray-700`;
cell.dataset.row = row;
cell.dataset.col = col;
gameBoard.appendChild(cell);
}
}
}
// Tetromino shapes
const SHAPES = [
[[1, 1, 1, 1]], // I
[[1, 1], [1, 1]], // O
[[1, 1, 1], [0, 1, 0]], // T
[[1, 1, 1], [1, 0, 0]], // L
[[1, 1, 1], [0, 0, 1]], // J
[[0, 1, 1], [1, 1, 0]], // S
[[1, 1, 0], [0, 1, 1]] // Z
];
// Create a new piece
function createPiece() {
const shape = SHAPES[Math.floor(Math.random() * SHAPES.length)];
const emoji = EMOJIS[Math.floor(Math.random() * EMOJIS.length)];
const color = COLORS[Math.floor(Math.random() * COLORS.length)];
return {
shape,
emoji,
color,
x: Math.floor(COLS / 2) - Math.floor(shape[0].length / 2),
y: 0
};
}
// Draw the board
function draw() {
// Clear the board
document.querySelectorAll('.cell').forEach(cell => {
cell.textContent = '';
cell.className = `cell w-[${BLOCK_SIZE}px] h-[${BLOCK_SIZE}px] border border-gray-700`;
});
// Draw fixed pieces
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
if (board[row][col]) {
const cell = document.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`);
if (cell) {
cell.textContent = board[row][col].emoji;
cell.classList.add(board[row][col].color, 'filled', 'pulse-emoji');
}
}
}
}
// Draw current piece
if (currentPiece) {
currentPiece.shape.forEach((row, y) => {
row.forEach((value, x) => {
if (value) {
const boardX = currentPiece.x + x;
const boardY = currentPiece.y + y;
if (boardY >= 0 && boardX >= 0 && boardX < COLS && boardY < ROWS) {
const cell = document.querySelector(`.cell[data-row="${boardY}"][data-col="${boardX}"]`);
if (cell) {
cell.textContent = currentPiece.emoji;
cell.classList.add(currentPiece.color, 'filled');
}
}
}
});
});
}
}
// Draw next piece preview
function drawNextPiece() {
nextPieceDisplay.innerHTML = '';
nextPieceDisplay.style.gridTemplateColumns = `repeat(4, ${BLOCK_SIZE/2}px)`;
// Center the piece
const offsetX = Math.floor((4 - nextPiece.shape[0].length) / 2);
const offsetY = Math.floor((4 - nextPiece.shape.length) / 2);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 4; col++) {
const cell = document.createElement('div');
cell.className = `w-[${BLOCK_SIZE/2}px] h-[${BLOCK_SIZE/2}px] flex items-center justify-center`;
const pieceRow = row - offsetY;
const pieceCol = col - offsetX;
if (pieceRow >= 0 && pieceRow < nextPiece.shape.length &&
pieceCol >= 0 && pieceCol < nextPiece.shape[0].length &&
nextPiece.shape[pieceRow][pieceCol]) {
cell.textContent = nextPiece.emoji;
cell.classList.add(nextPiece.color, 'text-xl');
}
nextPieceDisplay.appendChild(cell);
}
}
}
// Check for collisions
function collision(x, y, shape) {
for (let row = 0; row < shape.length; row++) {
for (let col = 0; col < shape[row].length; col++) {
if (shape[row][col]) {
const newX = x + col;
const newY = y + row;
if (newX < 0 || newX >= COLS || newY >= ROWS) {
return true;
}
if (newY >= 0 && board[newY][newX]) {
return true;
}
}
}
}
return false;
}
// Rotate piece
function rotate() {
if (!currentPiece) return;
const newShape = currentPiece.shape[0].map((_, i) =>
currentPiece.shape.map(row => row[i]).reverse()
);
if (!collision(currentPiece.x, currentPiece.y, newShape)) {
currentPiece.shape = newShape;
draw();
}
}
// Move piece
function move(dx, dy) {
if (!currentPiece || gameOver) return;
if (!collision(currentPiece.x + dx, currentPiece.y + dy, currentPiece.shape)) {
currentPiece.x += dx;
currentPiece.y += dy;
draw();
return true;
}
// If we couldn't move down, lock the piece
if (dy > 0) {
lockPiece();
}
return false;
}
// Lock piece in place
function lockPiece() {
currentPiece.shape.forEach((row, y) => {
row.forEach((value, x) => {
if (value) {
const boardX = currentPiece.x + x;
const boardY = currentPiece.y + y;
if (boardY >= 0) {
board[boardY][boardX] = {
emoji: currentPiece.emoji,
color: currentPiece.color
};
}
}
});
});
// Check for completed lines
checkLines();
// Get next piece
currentPiece = nextPiece;
nextPiece = createPiece();
drawNextPiece();
// Check if game over
if (collision(currentPiece.x, currentPiece.y, currentPiece.shape)) {
endGame();
}
}
// Check for completed lines
function checkLines() {
let linesCleared = 0;
for (let row = ROWS - 1; row >= 0; row--) {
if (board[row].every(cell => cell)) {
// Remove the line
board.splice(row, 1);
// Add new empty line at top
board.unshift(Array(COLS).fill(0));
linesCleared++;
row++; // Check the same row again
}
}
if (linesCleared > 0) {
// Update score
const linePoints = [0, 40, 100, 300, 1200];
score += linePoints[linesCleared] * level;
scoreDisplay.textContent = score;
// Update level every 10 lines
const newLevel = Math.floor(score / 1000) + 1;
if (newLevel > level) {
level = newLevel;
levelDisplay.textContent = level;
dropSpeed = Math.max(100, 1000 - (level - 1) * 100);
resetDropInterval();
}
// Play animation for cleared lines
playClearAnimation();
}
}
// Play animation when lines are cleared
function playClearAnimation() {
const cells = document.querySelectorAll('.cell.filled');
cells.forEach(cell => {
cell.style.transform = 'scale(1.2)';
cell.style.transition = 'transform 0.1s ease';
setTimeout(() => {
cell.style.transform = 'scale(1)';
}, 100);
});
}
// Drop piece automatically
function drop() {
move(0, 1);
}
// Hard drop - drop piece immediately
function hardDrop() {
while (move(0, 1)) {
// Keep moving down until we can't
}
}
// Reset drop interval when level changes
function resetDropInterval() {
if (dropInterval) {
clearInterval(dropInterval);
}
dropInterval = setInterval(drop, dropSpeed);
}
// End game
function endGame() {
gameOver = true;
clearInterval(dropInterval);
gameOverDisplay.classList.remove('hidden');
finalScoreDisplay.textContent = score;
}
// Start new game
function startGame() {
board = Array(ROWS).fill().map(() => Array(COLS).fill(0));
score = 0;
level = 1;
gameOver = false;
dropSpeed = 1000;
scoreDisplay.textContent = score;
levelDisplay.textContent = level;
gameOverDisplay.classList.add('hidden');
currentPiece = createPiece();
nextPiece = createPiece();
drawNextPiece();
draw();
resetDropInterval();
}
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (gameOver && e.key === ' ') {
startGame();
return;
}
switch (e.key) {
case 'ArrowLeft':
move(-1, 0);
break;
case 'ArrowRight':
move(1, 0);
break;
case 'ArrowDown':
move(0, 1);
break;
case 'ArrowUp':
rotate();
break;
case ' ':
hardDrop();
break;
}
});
// Restart button
restartBtn.addEventListener('click', startGame);
// Initialize and start game
initBoard();
startGame();
});
</script>
<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=fgalopo/test-space" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>