Spaces:
Running
Running
File size: 22,441 Bytes
74ba4e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Memory Challenge</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.game-tile {
transition: all 0.3s ease;
transform-style: preserve-3d;
}
.game-tile.flipped {
transform: rotateY(180deg);
}
.game-tile-face {
backface-visibility: hidden;
position: absolute;
width: 100%;
height: 100%;
border-radius: 0.5rem;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
}
.game-tile-front {
background: linear-gradient(135deg, #374151, #6B7280);
}
.game-tile-back {
background: linear-gradient(135deg, #3B82F6, #1D4ED8);
transform: rotateY(180deg);
}
.game-tile.matched .game-tile-front {
opacity: 0.2;
}
.confetti {
position: absolute;
width: 10px;
height: 10px;
background-color: #f00;
border-radius: 50%;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.pulse-animation {
animation: pulse 1.5s infinite;
}
</style>
</head>
<body class="bg-gray-900 text-white min-h-screen flex flex-col items-center justify-center p-4">
<div class="max-w-4xl w-full">
<header class="text-center mb-8">
<h1 class="text-4xl md:text-5xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-purple-600 mb-2">
Color Memory Challenge
</h1>
<p class="text-gray-300 mb-4">Match all pairs of colors to win!</p>
<div class="flex justify-center items-center space-x-6 mb-4">
<div class="bg-gray-800 px-4 py-2 rounded-lg">
<span class="text-blue-400"><i class="fas fa-stopwatch mr-2"></i></span>
<span id="timer">00:00</span>
</div>
<div class="bg-gray-800 px-4 py-2 rounded-lg">
<span class="text-yellow-400"><i class="fas fa-star mr-2"></i></span>
<span id="moves">0</span> moves
</div>
<div class="bg-gray-800 px-4 py-2 rounded-lg">
<span class="text-purple-400"><i class="fas fa-brain mr-2"></i></span>
<span id="memory">100%</span> memory
</div>
</div>
<button id="start-game" class="bg-gradient-to-r from-green-500 to-emerald-600 hover:from-green-600 hover:to-emerald-700 text-white font-bold py-3 px-6 rounded-full shadow-lg transition-all duration-300 transform hover:scale-105">
<i class="fas fa-play mr-2"></i> Start Game
</button>
</header>
<div id="game-board" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3 sm:gap-4 mb-8"></div>
<div id="game-modal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50 hidden">
<div class="bg-gray-800 rounded-xl p-8 max-w-lg w-full mx-4 text-center transform transition-all duration-500 scale-0">
<div class="text-4xl mb-4 text-green-400"><i class="fas fa-trophy"></i></div>
<h2 class="text-3xl font-bold mb-2">You Won!</h2>
<p class="text-gray-300 mb-6">Congratulations on completing the challenge!</p>
<div class="grid grid-cols-2 gap-4 mb-6">
<div class="bg-gray-700 p-3 rounded-lg">
<p class="text-sm text-gray-400">Time</p>
<p class="text-xl font-bold" id="modal-time"></p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<p class="text-sm text-gray-400">Moves</p>
<p class="text-xl font-bold" id="modal-moves"></p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<p class="text-sm text-gray-400">Memory Usage</p>
<p class="text-xl font-bold" id="modal-memory"></p>
</div>
<div class="bg-gray-700 p-3 rounded-lg">
<p class="text-sm text-gray-400">Difficulty</p>
<p class="text-xl font-bold" id="modal-difficulty"></p>
</div>
</div>
<div class="flex justify-center gap-4">
<button id="play-again" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-full transition-all">
Play Again
</button>
<button id="close-modal" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-6 rounded-full transition-all">
Close
</button>
</div>
</div>
</div>
</div>
<footer class="mt-auto text-center text-gray-500 py-4 text-sm">
<p>© 2023 Color Memory Challenge | Built with <i class="fas fa-heart text-red-500"></i> using HTML, CSS & JavaScript</p>
</footer>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Game state variables
let gameStarted = false;
let timerInterval;
let seconds = 0;
let moves = 0;
let memoryPercentage = 100;
let firstTile = null;
let secondTile = null;
let lockBoard = false;
let matchedPairs = 0;
let difficulty = 'medium';
let colorPairs = [];
let audioEnabled = true;
// DOM elements
const gameBoard = document.getElementById('game-board');
const startButton = document.getElementById('start-game');
const timerDisplay = document.getElementById('timer');
const movesDisplay = document.getElementById('moves');
const memoryDisplay = document.getElementById('memory');
const gameModal = document.getElementById('game-modal');
const modalTime = document.getElementById('modal-time');
const modalMoves = document.getElementById('modal-moves');
const modalMemory = document.getElementById('modal-memory');
const modalDifficulty = document.getElementById('modal-difficulty');
const playAgainButton = document.getElementById('play-again');
const closeModalButton = document.getElementById('close-modal');
// Color palettes for different difficulty levels
const colorPalettes = {
easy: [
'#FF5252', '#4CAF50', '#2196F3', '#FFC107',
'#9C27B0', '#00BCD4', '#E91E63', '#FF9800'
],
medium: [
'#FF5252', '#4CAF50', '#2196F3', '#FFC107',
'#9C27B0', '#00BCD4', '#E91E63', '#FF9800',
'#795548', '#607D8B', '#8BC34A', '#FF5722',
'#673AB7', '#009688', '#3F51B5', '#CDDC39'
],
hard: [
'#EF5350', '#66BB6A', '#42A5F5', '#FFA726',
'#AB47BC', '#26C6DA', '#EC407A', '#FF7043',
'#8D6E63', '#78909C', '#9CCC65', '#E57373',
'#7E57C2', '#26A69A', '#5C6BC0', '#DCE775',
'#FF5252', '#4CAF50', '#2196F3', '#FFC107',
'#9C27B0', '#00BCD4', '#E91E63', '#FF9800'
]
};
// Sounds
const sounds = {
flip: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-game-click-1114.mp3'),
match: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-unlock-game-notification-253.mp3'),
win: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-winning-chimes-2015.mp3'),
wrong: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-retro-arcade-lose-2027.mp3')
};
// Initialize the game
function initGame() {
// Reset game state
gameStarted = false;
clearInterval(timerInterval);
seconds = 0;
moves = 0;
memoryPercentage = 100;
matchedPairs = 0;
firstTile = null;
secondTile = null;
lockBoard = false;
// Update displays
timerDisplay.textContent = '00:00';
movesDisplay.textContent = '0';
memoryDisplay.textContent = '100%';
// Determine difficulty based on screen width
const screenWidth = window.innerWidth;
if (screenWidth < 640) { // Mobile
difficulty = 'easy';
colorPairs = [...colorPalettes.easy, ...colorPalettes.easy];
} else if (screenWidth < 1024) { // Tablet
difficulty = 'medium';
colorPairs = [...colorPalettes.medium, ...colorPalettes.medium];
} else { // Desktop
difficulty = 'hard';
colorPairs = [...colorPalettes.hard, ...colorPalettes.hard];
}
// Shuffle the colors
colorPairs = shuffleArray(colorPairs);
// Clear and rebuild the game board
gameBoard.innerHTML = '';
// Create tiles
colorPairs.forEach((color, index) => {
const tile = document.createElement('div');
tile.classList.add('game-tile', 'cursor-pointer', 'aspect-square', 'relative');
tile.dataset.index = index;
tile.dataset.color = color;
const frontFace = document.createElement('div');
frontFace.classList.add('game-tile-face', 'game-tile-front');
frontFace.innerHTML = '<i class="fas fa-question text-2xl sm:text-3xl opacity-70"></i>';
const backFace = document.createElement('div');
backFace.classList.add('game-tile-face', 'game-tile-back');
backFace.style.backgroundColor = color;
backFace.innerHTML = `<div class="w-1/2 h-1/2 rounded-lg" style="background-color: ${color}; border: 2px solid white;"></div>`;
tile.appendChild(frontFace);
tile.appendChild(backFace);
tile.addEventListener('click', flipTile);
gameBoard.appendChild(tile);
});
// Update modal difficulty display
modalDifficulty.textContent = difficulty.charAt(0).toUpperCase() + difficulty.slice(1);
// Reset start button
startButton.innerHTML = '<i class="fas fa-play mr-2"></i> Start Game';
startButton.classList.remove('bg-gradient-to-r', 'from-red-500', 'to-red-600');
startButton.classList.add('bg-gradient-to-r', 'from-green-500', 'to-emerald-600', 'hover:from-green-600', 'hover:to-emerald-700');
// Show memory tiles briefly at start
if (gameStarted) {
showTilesBriefly();
}
}
// Shuffle array using Fisher-Yates algorithm
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// Start the game
function startGame() {
if (gameStarted) return;
gameStarted = true;
startButton.innerHTML = '<i class="fas fa-sync-alt mr-2"></i> Restart';
startButton.classList.remove('bg-gradient-to-r', 'from-green-500', 'to-emerald-600', 'hover:from-green-600', 'hover:to-emerald-700');
startButton.classList.add('bg-gradient-to-r', 'from-red-500', 'to-red-600', 'hover:from-red-600', 'hover:to-red-700');
// Start timer
seconds = 0;
updateTimer();
timerInterval = setInterval(() => {
seconds++;
updateTimer();
// Reduce memory percentage over time
if (seconds % 5 === 0 && memoryPercentage > 20) {
memoryPercentage -= 1;
memoryDisplay.textContent = `${memoryPercentage}%`;
}
}, 1000);
// Show tiles briefly at start
showTilesBriefly();
}
// Update timer display
function updateTimer() {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
timerDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
}
// Show all tiles briefly at game start
function showTilesBriefly() {
const tiles = document.querySelectorAll('.game-tile');
tiles.forEach(tile => tile.classList.add('flipped'));
setTimeout(() => {
tiles.forEach(tile => tile.classList.remove('flipped'));
}, 2000);
}
// Flip a tile
function flipTile() {
if (!gameStarted) {
startGame();
return;
}
if (lockBoard || this.classList.contains('flipped') || this.classList.contains('matched')) {
return;
}
// Play sound
if (audioEnabled) sounds.flip.play();
this.classList.add('flipped');
if (!firstTile) {
firstTile = this;
return;
}
secondTile = this;
moves++;
movesDisplay.textContent = moves;
checkForMatch();
}
// Check if the flipped tiles match
function checkForMatch() {
const isMatch = firstTile.dataset.color === secondTile.dataset.color;
if (isMatch) {
disableTiles();
// Play match sound
if (audioEnabled) sounds.match.play();
matchedPairs++;
// Check if all pairs are matched
if (matchedPairs === colorPairs.length / 2) {
setTimeout(endGame, 500);
}
} else {
unflipTiles();
// Play wrong sound
if (audioEnabled) sounds.wrong.play();
}
}
// Disable matched tiles
function disableTiles() {
firstTile.classList.add('matched');
secondTile.classList.add('matched');
// Add some visual feedback
firstTile.classList.add('pulse-animation');
secondTile.classList.add('pulse-animation');
setTimeout(() => {
firstTile.classList.remove('pulse-animation');
secondTile.classList.remove('pulse-animation');
}, 1000);
resetBoard();
}
// Unflip tiles that don't match
function unflipTiles() {
lockBoard = true;
setTimeout(() => {
firstTile.classList.remove('flipped');
secondTile.classList.remove('flipped');
resetBoard();
}, 1000);
}
// Reset the board state
function resetBoard() {
[firstTile, secondTile] = [null, null];
lockBoard = false;
}
// End the game
function endGame() {
clearInterval(timerInterval);
// Play win sound
if (audioEnabled) sounds.win.play();
// Update modal with results
modalTime.textContent = timerDisplay.textContent;
modalMoves.textContent = moves;
modalMemory.textContent = `${memoryPercentage}%`;
// Show modal with animation
const modalContent = gameModal.querySelector('.transform');
gameModal.classList.remove('hidden');
setTimeout(() => {
modalContent.classList.remove('scale-0');
modalContent.classList.add('scale-100');
}, 50);
// Add confetti effect
createConfetti();
}
// Create confetti effect
function createConfetti() {
const colors = ['#f00', '#0f0', '#00f', '#ff0', '#f0f', '#0ff'];
const container = document.body;
for (let i = 0; i < 100; i++) {
const confetti = document.createElement('div');
confetti.classList.add('confetti');
// Random properties
const color = colors[Math.floor(Math.random() * colors.length)];
const size = Math.random() * 10 + 5;
const posX = Math.random() * window.innerWidth;
const delay = Math.random() * 3;
const duration = Math.random() * 3 + 2;
confetti.style.backgroundColor = color;
confetti.style.width = `${size}px`;
confetti.style.height = `${size}px`;
confetti.style.left = `${posX}px`;
confetti.style.top = '-10px';
confetti.style.zIndex = '1000';
// Animation
confetti.style.animation = `fall ${duration}s ease-in ${delay}s forwards`;
// Create keyframes dynamically
const keyframes = `
@keyframes fall {
to {
transform: translateY(${window.innerHeight + 10}px) rotate(${Math.random() * 360}deg);
opacity: 0;
}
}
`;
const style = document.createElement('style');
style.innerHTML = keyframes;
document.head.appendChild(style);
container.appendChild(confetti);
// Remove after animation
setTimeout(() => {
confetti.remove();
style.remove();
}, (duration + delay) * 1000);
}
}
// Event listeners
startButton.addEventListener('click', initGame);
playAgainButton.addEventListener('click', () => {
const modalContent = gameModal.querySelector('.transform');
modalContent.classList.remove('scale-100');
modalContent.classList.add('scale-0');
setTimeout(() => {
gameModal.classList.add('hidden');
initGame();
startGame();
}, 300);
});
closeModalButton.addEventListener('click', () => {
const modalContent = gameModal.querySelector('.transform');
modalContent.classList.remove('scale-100');
modalContent.classList.add('scale-0');
setTimeout(() => {
gameModal.classList.add('hidden');
initGame();
}, 300);
});
// Initialize the game
initGame();
});
</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=A3qualityo/game" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |