Spaces:
Running

anycoder-d71be70c / index.html
withchan's picture
Upload folder using huggingface_hub
d66790b verified
Raw History Blame Contribute Delete
26 kB
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2048 - ํ˜„๋Œ€์ ์ธ ํผ์ฆ ๊ฒŒ์ž„</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap');
:root {
--tile-size: clamp(60px, 18vw, 100px);
--gap: clamp(8px, 2vw, 12px);
--board-padding: clamp(8px, 2vw, 12px);
--primary-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--glass-bg: rgba(255, 255, 255, 0.1);
--glass-border: rgba(255, 255, 255, 0.2);
}
* {
box-sizing: border-box;
touch-action: none;
}
body {
font-family: 'Inter', sans-serif;
background: var(--primary-bg);
min-height: 100vh;
overflow-x: hidden;
user-select: none;
}
/* Glassmorphism Effects */
.glass-panel {
background: var(--glass-bg);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid var(--glass-border);
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}
.game-container {
position: relative;
width: fit-content;
margin: 0 auto;
padding: var(--board-padding);
border-radius: 20px;
background: rgba(0, 0, 0, 0.2);
touch-action: none;
}
.grid-container {
display: grid;
grid-template-columns: repeat(4, var(--tile-size));
grid-template-rows: repeat(4, var(--tile-size));
gap: var(--gap);
position: relative;
}
.grid-cell {
background: rgba(255, 255, 255, 0.1);
border-radius: 12px;
width: var(--tile-size);
height: var(--tile-size);
}
.tile-container {
position: absolute;
top: var(--board-padding);
left: var(--board-padding);
right: var(--board-padding);
bottom: var(--board-padding);
pointer-events: none;
}
.tile {
position: absolute;
width: var(--tile-size);
height: var(--tile-size);
border-radius: 12px;
display: flex;
justify-content: center;
align-items: center;
font-weight: 800;
font-size: clamp(1.5rem, 5vw, 2rem);
transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
z-index: 10;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.tile-new {
animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.tile-merged {
animation: merge 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
z-index: 20;
}
@keyframes popIn {
0% { transform: scale(0); opacity: 0; }
100% { transform: scale(1); opacity: 1; }
}
@keyframes merge {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
/* Tile Colors */
.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile-16 { background: #f59563; color: #f9f6f2; }
.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile-128 { background: #edcf72; color: #f9f6f2; font-size: clamp(1.2rem, 4vw, 1.8rem); box-shadow: 0 0 10px rgba(237, 207, 114, 0.3); }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: clamp(1.2rem, 4vw, 1.8rem); box-shadow: 0 0 15px rgba(237, 204, 97, 0.4); }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: clamp(1.2rem, 4vw, 1.8rem); box-shadow: 0 0 20px rgba(237, 200, 80, 0.5); }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(1rem, 3.5vw, 1.5rem); box-shadow: 0 0 25px rgba(237, 197, 63, 0.6); }
.tile-2048 { background: linear-gradient(135deg, #edc22e, #f9d71c); color: #f9f6f2; font-size: clamp(1rem, 3.5vw, 1.5rem); box-shadow: 0 0 30px rgba(237, 194, 46, 0.7); animation: glow 2s ease-in-out infinite alternate; }
@keyframes glow {
from { box-shadow: 0 0 30px rgba(237, 194, 46, 0.7); }
to { box-shadow: 0 0 40px rgba(237, 194, 46, 0.9), 0 0 60px rgba(237, 194, 46, 0.4); }
}
.score-box {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 0.75rem 1.5rem;
min-width: 100px;
text-align: center;
transition: transform 0.2s;
}
.score-box:hover {
transform: translateY(-2px);
}
.score-label {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: rgba(255, 255, 255, 0.8);
margin-bottom: 0.25rem;
}
.score-value {
font-size: 1.5rem;
font-weight: 800;
color: white;
transition: all 0.3s;
}
.score-add {
position: absolute;
color: #f9d71c;
font-weight: bold;
font-size: 1.5rem;
pointer-events: none;
animation: floatUp 0.8s ease-out forwards;
z-index: 100;
}
@keyframes floatUp {
0% { opacity: 1; transform: translateY(0) scale(1); }
100% { opacity: 0; transform: translateY(-50px) scale(1.5); }
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
color: white;
padding: 0.75rem 2rem;
border-radius: 12px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
position: relative;
overflow: hidden;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-primary::after {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
transition: 0.5s;
}
.btn-primary:hover::after {
left: 100%;
}
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(5px);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
.modal.active {
opacity: 1;
pointer-events: all;
}
.modal-content {
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 24px;
padding: 2.5rem;
text-align: center;
transform: scale(0.8);
transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
max-width: 90%;
width: 400px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal.active .modal-content {
transform: scale(1);
}
.control-btn {
width: 50px;
height: 50px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
color: white;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.control-btn:hover {
background: rgba(255, 255, 255, 0.2);
transform: scale(1.1);
}
.control-btn:active {
transform: scale(0.95);
}
/* Particle effects */
.particle {
position: absolute;
width: 6px;
height: 6px;
background: rgba(255, 255, 255, 0.5);
border-radius: 50%;
pointer-events: none;
animation: particleFloat 3s infinite ease-in-out;
}
@keyframes particleFloat {
0%, 100% { transform: translateY(0) translateX(0); opacity: 0; }
10% { opacity: 1; }
90% { opacity: 1; }
100% { transform: translateY(-100vh) translateX(50px); }
}
.built-with {
font-size: 0.875rem;
color: rgba(255, 255, 255, 0.6);
text-decoration: none;
transition: all 0.3s;
display: inline-flex;
align-items: center;
gap: 0.5rem;
}
.built-with:hover {
color: rgba(255, 255, 255, 1);
transform: translateY(-1px);
}
@media (max-width: 480px) {
.grid-container {
gap: calc(var(--gap) * 0.8);
}
}
</style>
</head>
<body class="flex flex-col items-center justify-center min-h-screen p-4">
<!-- Background Particles -->
<div id="particles" class="fixed inset-0 pointer-events-none overflow-hidden"></div>
<!-- Header -->
<header class="w-full max-w-lg mb-6 flex justify-between items-center">
<div>
<h1 class="text-5xl font-extrabold text-white mb-1 tracking-tight" style="text-shadow: 0 4px 12px rgba(0,0,0,0.3);">2048</h1>
<p class="text-white/70 text-sm">ํƒ€์ผ์„ ํ•ฉ์ณ์„œ <span class="text-yellow-300 font-bold">2048</span>์„ ๋งŒ๋“ค์–ด๋ณด์„ธ์š”!</p>
</div>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="built-with glass-panel px-4 py-2 rounded-full">
<i class="fas fa-code"></i>
<span>Built with anycoder</span>
</a>
</header>
<!-- Score Board -->
<div class="w-full max-w-lg flex gap-4 mb-6 justify-center">
<div class="score-box relative">
<div class="score-label">์ ์ˆ˜</div>
<div class="score-value" id="score">0</div>
</div>
<div class="score-box">
<div class="score-label">์ตœ๊ณ  ์ ์ˆ˜</div>
<div class="score-value" id="best-score">0</div>
</div>
<button class="btn-primary flex items-center gap-2" onclick="game.restart()">
<i class="fas fa-rotate-right"></i>
<span class="hidden sm:inline">์ƒˆ ๊ฒŒ์ž„</span>
</button>
</div>
<!-- Game Container -->
<div class="game-container glass-panel" id="game-container">
<div class="grid-container" id="grid-container">
<!-- Grid cells will be generated by JS -->
</div>
<div class="tile-container" id="tile-container"></div>
</div>
<!-- Mobile Controls -->
<div class="mt-8 grid grid-cols-3 gap-2 sm:hidden">
<div></div>
<button class="control-btn" onclick="game.move('up')"><i class="fas fa-arrow-up"></i></button>
<div></div>
<button class="control-btn" onclick="game.move('left')"><i class="fas fa-arrow-left"></i></button>
<button class="control-btn" onclick="game.move('down')"><i class="fas fa-arrow-down"></i></button>
<button class="control-btn" onclick="game.move('right')"><i class="fas fa-arrow-right"></i></button>
</div>
<!-- Instructions -->
<div class="mt-6 text-center text-white/60 text-sm max-w-md">
<p class="hidden sm:block"><i class="fas fa-keyboard mr-2"></i>๋ฐฉํ–ฅํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํƒ€์ผ์„ ์ด๋™ํ•˜์„ธ์š”</p>
<p class="sm:hidden"><i class="fas fa-hand-pointer mr-2"></i>ํ™”๋ฉด์„ ์Šค์™€์ดํ”„ํ•˜๊ฑฐ๋‚˜ ๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•˜์„ธ์š”</p>
</div>
<!-- Game Over Modal -->
<div class="modal" id="game-over-modal">
<div class="modal-content">
<div class="text-6xl mb-4">๐Ÿ˜ข</div>
<h2 class="text-3xl font-bold text-white mb-2">๊ฒŒ์ž„ ์˜ค๋ฒ„!</h2>
<p class="text-gray-400 mb-6">๋” ์ด์ƒ ์›€์ง์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.</p>
<div class="text-2xl font-bold text-yellow-400 mb-6">์ ์ˆ˜: <span id="final-score">0</span></div>
<button class="btn-primary w-full text-lg" onclick="game.restart()">
<i class="fas fa-rotate-right mr-2"></i>๋‹ค์‹œ ์‹œ์ž‘
</button>
</div>
</div>
<!-- Win Modal -->
<div class="modal" id="win-modal">
<div class="modal-content" style="background: linear-gradient(135deg, #1a1a2e 0%, #2d1b4e 100%); border-color: rgba(237, 194, 46, 0.3);">
<div class="text-6xl mb-4 animate-bounce">๐ŸŽ‰</div>
<h2 class="text-3xl font-bold text-white mb-2">์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค!</h2>
<p class="text-gray-400 mb-4">2048 ํƒ€์ผ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค!</p>
<div class="text-lg text-yellow-300 mb-6">๊ณ„์†ํ•ด์„œ ๋” ๋†’์€ ์ ์ˆ˜์— ๋„์ „ํ•ด๋ณด์„ธ์š”!</div>
<div class="flex gap-3">
<button class="btn-primary flex-1" onclick="game.continueGame()">
๊ณ„์†ํ•˜๊ธฐ
</button>
<button class="btn-primary flex-1" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);" onclick="game.restart()">
์ƒˆ ๊ฒŒ์ž„
</button>
</div>
</div>
</div>
<script>
class Game2048 {
constructor() {
this.size = 4;
this.grid = [];
this.score = 0;
this.bestScore = parseInt(localStorage.getItem('bestScore')) || 0;
this.won = false;
this.over = false;
this.tileContainer = document.getElementById('tile-container');
this.scoreElement = document.getElementById('score');
this.bestScoreElement = document.getElementById('best-score');
this.gameContainer = document.getElementById('game-container');
this.init();
this.setupInput();
this.createParticles();
}
init() {
// Create grid cells
const gridContainer = document.getElementById('grid-container');
gridContainer.innerHTML = '';
for (let i = 0; i < this.size * this.size; i++) {
const cell = document.createElement('div');
cell.className = 'grid-cell';
gridContainer.appendChild(cell);
}
this.grid = Array(this.size).fill().map(() => Array(this.size).fill(0));
this.score = 0;
this.won = false;
this.over = false;
this.updateScore();
// Add initial tiles
this.addRandomTile();
this.addRandomTile();
this.updateDisplay();
}
createParticles() {
const container = document.getElementById('particles');
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 3 + 's';
particle.style.animationDuration = (3 + Math.random() * 2) + 's';
container.appendChild(particle);
}
}
setupInput() {
// Keyboard input
document.addEventListener('keydown', (e) => {
if (this.over && e.key !== 'Enter') return;
switch(e.key) {
case 'ArrowUp': this.move('up'); e.preventDefault(); break;
case 'ArrowDown': this.move('down'); e.preventDefault(); break;
case 'ArrowLeft': this.move('left'); e.preventDefault(); break;
case 'ArrowRight': this.move('right'); e.preventDefault(); break;
}
});
// Touch input
let touchStartX, touchStartY;
const minSwipeDistance = 30;
this.gameContainer.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
}, { passive: true });
this.gameContainer.addEventListener('touchend', (e) => {
if (!touchStartX || !touchStartY || this.over) return;
const touchEndX = e.changedTouches[0].clientX;
const touchEndY = e.changedTouches[0].clientY;
const dx = touchEndX - touchStartX;
const dy = touchEndY - touchStartY;
if (Math.abs(dx) < minSwipeDistance && Math.abs(dy) < minSwipeDistance) return;
if (Math.abs(dx) > Math.abs(dy)) {
this.move(dx > 0 ? 'right' : 'left');
} else {
this.move(dy > 0 ? 'down' : 'up');
}
touchStartX = null;
touchStartY = null;
}, { passive: true });
}
addRandomTile() {
const emptyCells = [];
for (let r = 0; r < this.size; r++) {
for (let c = 0; c < this.size; c++) {
if (this.grid[r][c] === 0) emptyCells.push({r, c});
}
}
if (emptyCells.length > 0) {
const {r, c} = emptyCells[Math.floor(Math.random() * emptyCells.length)];
this.grid[r][c] = Math.random() < 0.9 ? 2 : 4;
return {r, c, value: this.grid[r][c], isNew: true};
}
return null;
}
move(direction) {
if (this.over) return;
const rotated = this.getRotatedGrid(direction);
let moved = false;
const mergedPositions = [];
// Process each row
for (let r = 0; r < this.size; r++) {
const row = rotated[r].filter(x => x !== 0);
const newRow = [];
let i = 0;
while (i < row.length) {
if (i < row.length - 1 && row[i] === row[i + 1]) {
const merged = row[i] * 2;
newRow.push(merged);
this.score += merged;
mergedPositions.push({r, c: newRow.length - 1, value: merged});
i += 2;
moved = true;
if (merged === 2048 && !this.won) this.won = true;
} else {
newRow.push(row[i]);
i++;
}
}
while (newRow.length < this.size) newRow.push(0);
for (let c = 0; c < this.size; c++) {
if (rotated[r][c] !== newRow[c]) moved = true;
rotated[r][c] = newRow[c];
}
}
if (!moved) return;
this.setRotatedGrid(rotated, direction);
this.updateScore();
const newTile = this.addRandomTile();
this.updateDisplay(newTile, mergedPositions);
if (this.won) {
setTimeout(() => this.showWinModal(), 300);
} else if (this.isGameOver()) {
setTimeout(() => this.showGameOverModal(), 300);
}
}
getRotatedGrid(direction) {
let grid = this.grid.map(row => [...row]);
if (direction === 'up') return grid;
if (direction === 'down') return grid.reverse();
if (direction === 'left') return this.transpose(grid);
if (direction === 'right') return this.transpose(grid).reverse();
return grid;
}
setRotatedGrid(grid, direction) {
if (direction === 'up') this.grid = grid;
else if (direction === 'down') this.grid = grid.reverse();
else if (direction === 'left') this.grid = this.transpose(grid);
else if (direction === 'right') this.grid = this.transpose(grid.reverse());
}
transpose(grid) {
return grid[0].map((_, i) => grid.map(row => row[i]));
}
updateDisplay(newTile = null, mergedPositions = []) {
this.tileContainer.innerHTML = '';
for (let r = 0; r < this.size; r++) {
for (let c = 0; c < this.size; c++) {
const value = this.grid[r][c];
if (value !== 0) {
const tile = document.createElement('div');
tile.className = `tile tile-${value}`;
tile.textContent = value;
// Calculate position
const gap = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--gap'));
const tileSize = parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--tile-size'));
const x = c * (tileSize + gap);
const y = r * (tileSize + gap);
tile.style.transform = `translate(${x}px, ${y}px)`;
// Check if this is a new tile
if (newTile && newTile.r === r && newTile.c === c) {
tile.classList.add('tile-new');
}
// Check if this tile was merged
if (mergedPositions.some(m => m.r === r && m.c === c)) {
tile.classList.add('tile-merged');
}
this.tileContainer.appendChild(tile);
}
}
}
}
updateScore() {
this.scoreElement.textContent = this.score;
this.bestScoreElement.textContent = this.bestScore;
if (this.score > this.bestScore) {
this.bestScore = this.score;
localStorage.setItem('bestScore', this.bestScore);
this.bestScoreElement.textContent = this.bestScore;
}
}
isGameOver() {
// Check for empty cells
for (let r = 0; r < this.size; r++) {
for (let c = 0; c < this.size; c++) {
if (this.grid[r][c] === 0) return false;
}
}
// Check for possible merges
for (let r = 0; r < this.size; r++) {
for (let c = 0; c < this.size; c++) {
const val = this.grid[r][c];
if ((r < this.size - 1 && this.grid[r + 1][c] === val) ||
(c < this.size - 1 && this.grid[r][c + 1] === val)) {
return false;
}
}
}
return true;
}
showGameOverModal() {
this.over = true;
document.getElementById('final-score').textContent = this.score;
document.getElementById('game-over-modal').classList.add('active');
}
showWinModal() {
document.getElementById('win-modal').classList.add('active');
}
continueGame() {
document.getElementById('win-modal').classList.remove('active');
}
restart() {
document.getElementById('game-over-modal').classList.remove('active');
document.getElementById('win-modal').classList.remove('active');
this.tileContainer.innerHTML = '';
this.init();
}
}
// Initialize game
const game = new Game2048();
</script>
</body>
</html>