File size: 13,256 Bytes
100702b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Memory Match Game</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>
        .card {
            perspective: 1000px;
            transform-style: preserve-3d;
            transition: all 0.5s ease;
        }
        
        .card-inner {
            position: relative;
            width: 100%;
            height: 100%;
            transform-style: preserve-3d;
            transition: transform 0.6s;
        }
        
        .card.flipped .card-inner {
            transform: rotateY(180deg);
        }
        
        .card-front, .card-back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .card-front {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            transform: rotateY(180deg);
        }
        
        .card-back {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .matched {
            opacity: 0.6;
            transform: scale(0.95);
        }
        
        @keyframes celebration {
            0% { transform: scale(1); }
            50% { transform: scale(1.2); }
            100% { transform: scale(1); }
        }
        
        .celebration {
            animation: celebration 0.5s ease;
        }
        
        .confetti {
            position: absolute;
            width: 10px;
            height: 10px;
            background-color: #f00;
            opacity: 0;
        }
    </style>
</head>
<body class="bg-gray-100 min-h-screen flex flex-col items-center justify-center p-4">
    <div class="w-full max-w-4xl mx-auto">
        <div class="flex justify-between items-center mb-8">
            <h1 class="text-3xl font-bold text-indigo-800">Memory Match</h1>
            <div class="flex space-x-6">
                <div class="bg-white p-3 rounded-lg shadow-md flex items-center">
                    <i class="fas fa-stopwatch text-indigo-600 mr-2"></i>
                    <span id="timer" class="font-semibold">00:00</span>
                </div>
                <div class="bg-white p-3 rounded-lg shadow-md flex items-center">
                    <i class="fas fa-star text-yellow-500 mr-2"></i>
                    <span id="score" class="font-semibold">0</span>
                </div>
                <div class="bg-white p-3 rounded-lg shadow-md flex items-center">
                    <i class="fas fa-redo-alt text-indigo-600 mr-2"></i>
                    <button id="restart" class="font-semibold">Restart</button>
                </div>
            </div>
        </div>
        
        <div class="grid grid-cols-4 gap-4" id="game-board">
            <!-- Cards will be generated here by JavaScript -->
        </div>
        
        <div id="win-message" class="hidden mt-8 p-6 bg-gradient-to-r from-green-400 to-blue-500 rounded-lg text-white text-center">
            <h2 class="text-2xl font-bold mb-2">Congratulations! 🎉</h2>
            <p class="mb-4">You matched all pairs in <span id="final-time">00:00</span> with <span id="final-moves">0</span> moves!</p>
            <button id="play-again" class="px-6 py-2 bg-white text-indigo-600 rounded-full font-semibold hover:bg-gray-100 transition">Play Again</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const gameBoard = document.getElementById('game-board');
            const timerElement = document.getElementById('timer');
            const scoreElement = document.getElementById('score');
            const restartButton = document.getElementById('restart');
            const winMessage = document.getElementById('win-message');
            const finalTimeElement = document.getElementById('final-time');
            const finalMovesElement = document.getElementById('final-moves');
            const playAgainButton = document.getElementById('play-again');
            
            const icons = [
                'fa-heart', 'fa-star', 'fa-moon', 'fa-sun', 
                'fa-cloud', 'fa-bolt', 'fa-bell', 'fa-key',
                'fa-flag', 'fa-gem', 'fa-ghost', 'fa-hashtag'
            ];
            
            let cards = [];
            let hasFlippedCard = false;
            let lockBoard = false;
            let firstCard, secondCard;
            let matchedPairs = 0;
            let moves = 0;
            let timerInterval;
            let seconds = 0;
            
            // Initialize game
            initGame();
            
            function initGame() {
                // Reset game state
                matchedPairs = 0;
                moves = 0;
                seconds = 0;
                clearInterval(timerInterval);
                updateScore();
                updateTimer();
                winMessage.classList.add('hidden');
                
                // Create pairs of cards
                const gameIcons = [...icons.slice(0, 6), ...icons.slice(0, 6)];
                shuffleArray(gameIcons);
                
                // Clear the game board
                gameBoard.innerHTML = '';
                cards = [];
                
                // Create card elements
                gameIcons.forEach((icon, index) => {
                    const card = document.createElement('div');
                    card.className = 'card h-32 cursor-pointer';
                    card.dataset.index = index;
                    
                    card.innerHTML = `
                        <div class="card-inner h-full">
                            <div class="card-front">
                                <i class="fas ${icon} text-4xl text-indigo-600"></i>
                            </div>
                            <div class="card-back">
                                <i class="fas fa-question text-4xl"></i>
                            </div>
                        </div>
                    `;
                    
                    card.addEventListener('click', flipCard);
                    gameBoard.appendChild(card);
                    cards.push(card);
                });
                
                // Start timer
                timerInterval = setInterval(() => {
                    seconds++;
                    updateTimer();
                }, 1000);
            }
            
            function flipCard() {
                if (lockBoard) return;
                if (this === firstCard) return;
                if (this.classList.contains('matched')) return;
                
                this.classList.add('flipped');
                
                if (!hasFlippedCard) {
                    // First click
                    hasFlippedCard = true;
                    firstCard = this;
                    return;
                }
                
                // Second click
                secondCard = this;
                moves++;
                updateScore();
                checkForMatch();
            }
            
            function checkForMatch() {
                const firstIcon = firstCard.querySelector('.card-front i').className;
                const secondIcon = secondCard.querySelector('.card-front i').className;
                
                const isMatch = firstIcon === secondIcon;
                
                if (isMatch) {
                    disableCards();
                    matchedPairs++;
                    
                    if (matchedPairs === 6) {
                        clearInterval(timerInterval);
                        setTimeout(() => {
                            showWinMessage();
                            createConfetti();
                        }, 500);
                    }
                } else {
                    unflipCards();
                }
            }
            
            function disableCards() {
                firstCard.classList.add('matched');
                secondCard.classList.add('matched');
                firstCard.classList.add('celebration');
                secondCard.classList.add('celebration');
                
                setTimeout(() => {
                    firstCard.classList.remove('celebration');
                    secondCard.classList.remove('celebration');
                }, 500);
                
                resetBoard();
            }
            
            function unflipCards() {
                lockBoard = true;
                
                setTimeout(() => {
                    firstCard.classList.remove('flipped');
                    secondCard.classList.remove('flipped');
                    resetBoard();
                }, 1000);
            }
            
            function resetBoard() {
                [hasFlippedCard, lockBoard] = [false, false];
                [firstCard, secondCard] = [null, null];
            }
            
            function updateScore() {
                scoreElement.textContent = moves;
            }
            
            function updateTimer() {
                const minutes = Math.floor(seconds / 60).toString().padStart(2, '0');
                const secs = (seconds % 60).toString().padStart(2, '0');
                timerElement.textContent = `${minutes}:${secs}`;
            }
            
            function showWinMessage() {
                finalTimeElement.textContent = timerElement.textContent;
                finalMovesElement.textContent = moves;
                winMessage.classList.remove('hidden');
            }
            
            function createConfetti() {
                for (let i = 0; i < 100; i++) {
                    const confetti = document.createElement('div');
                    confetti.className = 'confetti';
                    
                    // Random position
                    const xPos = Math.random() * window.innerWidth;
                    const yPos = Math.random() * -100;
                    
                    // Random color
                    const colors = ['#f00', '#0f0', '#00f', '#ff0', '#f0f', '#0ff'];
                    const randomColor = colors[Math.floor(Math.random() * colors.length)];
                    
                    // Random size
                    const size = Math.random() * 10 + 5;
                    
                    // Random animation duration
                    const duration = Math.random() * 3 + 2;
                    
                    confetti.style.left = `${xPos}px`;
                    confetti.style.top = `${yPos}px`;
                    confetti.style.backgroundColor = randomColor;
                    confetti.style.width = `${size}px`;
                    confetti.style.height = `${size}px`;
                    confetti.style.borderRadius = '50%';
                    
                    // Animation
                    confetti.style.transition = `all ${duration}s linear`;
                    confetti.style.opacity = '1';
                    
                    document.body.appendChild(confetti);
                    
                    setTimeout(() => {
                        confetti.style.top = `${window.innerHeight}px`;
                        confetti.style.opacity = '0';
                    }, 10);
                    
                    // Remove after animation
                    setTimeout(() => {
                        confetti.remove();
                    }, duration * 1000);
                }
            }
            
            // Helper function to shuffle array
            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;
            }
            
            // Event listeners
            restartButton.addEventListener('click', initGame);
            playAgainButton.addEventListener('click', 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=has200/memory-match" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>