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
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
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AzerType - Jeu de Dactylographie</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">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3b82f6',
                        secondary: '#1e40af',
                        accent: '#f59e0b',
                        dark: '#1e293b',
                        light: '#f8fafc'
                    }
                }
            }
        }
    </script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
        
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #1e3c72, #2a5298);
            min-height: 100vh;
        }
        
        .typing-word {
            font-size: 2.5rem;
            font-weight: 700;
            letter-spacing: 2px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.2);
            transition: all 0.3s ease;
        }
        
        .typing-input {
            font-size: 1.5rem;
            letter-spacing: 1px;
        }
        
        .timer {
            font-size: 3rem;
            font-weight: 700;
        }
        
        .leaderboard-item:nth-child(1) {
            background: linear-gradient(to right, #fde047, #f59e0b);
        }
        
        .leaderboard-item:nth-child(2) {
            background: linear-gradient(to right, #d1d5db, #9ca3af);
        }
        
        .leaderboard-item:nth-child(3) {
            background: linear-gradient(to right, #fca5a5, #ef4444);
        }
        
        .pulse {
            animation: pulse 1.5s infinite;
        }
        
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        
        .correct {
            color: #10b981;
        }
        
        .incorrect {
            color: #ef4444;
        }
        
        .progress-bar {
            transition: width 0.5s ease;
        }
    </style>
</head>
<body class="text-gray-800">
    <div class="container mx-auto px-4 py-8">
        <header class="text-center mb-10">
            <h1 class="text-4xl md:text-5xl font-bold text-white mb-2">AzerType</h1>
            <p class="text-xl text-blue-200">Testez votre vitesse de frappe !</p>
        </header>

        <div class="grid grid-cols-1 lg:grid-cols-2 gap-8 max-w-4xl mx-auto">
            <!-- Game Panel -->
            <div class="bg-white rounded-2xl shadow-xl p-6">
                <!-- Player Setup -->
                <div id="playerSetup" class="mb-8">
                    <h2 class="text-2xl font-bold text-center mb-6 text-gray-700">Entrez votre pseudo</h2>
                    <div class="max-w-md mx-auto">
                        <div class="flex">
                            <input type="text" id="playerName" placeholder="Votre pseudo" 
                                   class="flex-grow px-4 py-3 rounded-l-lg border-2 border-r-0 border-blue-300 focus:outline-none focus:border-blue-500">
                            <button id="startGameBtn" 
                                    class="bg-primary hover:bg-secondary text-white px-6 py-3 rounded-r-lg font-medium transition duration-300">
                                Commencer
                            </button>
                        </div>
                    </div>
                </div>

                <!-- Game Interface -->
                <div id="gameInterface" class="hidden">
                    <div class="flex justify-between items-center mb-8">
                        <div class="text-center">
                            <div class="text-sm text-gray-500">Temps restant</div>
                            <div id="timer" class="timer text-red-500">30</div>
                        </div>
                        <div class="text-center">
                            <div class="text-sm text-gray-500">Score</div>
                            <div id="score" class="text-3xl font-bold text-primary">0</div>
                        </div>
                        <div class="text-center">
                            <div class="text-sm text-gray-500">Mots</div>
                            <div id="wordCount" class="text-3xl font-bold text-green-500">0</div>
                        </div>
                    </div>

                    <div class="text-center mb-10">
                        <div id="currentWord" class="typing-word text-gray-800 mb-8">Chargement...</div>
                        <input type="text" id="typingInput" 
                               class="typing-input w-full max-w-md mx-auto px-6 py-4 border-2 border-blue-300 rounded-lg focus:outline-none focus:border-blue-500 text-center"
                               placeholder="Tapez le mot ici..." autocomplete="off" disabled>
                    </div>

                    <div class="mb-8">
                        <div class="flex justify-between text-sm text-gray-600 mb-1">
                            <span>Progression</span>
                            <span id="progressText">0%</span>
                        </div>
                        <div class="h-3 bg-gray-200 rounded-full overflow-hidden">
                            <div id="progressBar" class="h-full bg-primary rounded-full w-0"></div>
                        </div>
                    </div>

                    <div class="text-center hidden" id="gameOver">
                        <div class="bg-blue-50 rounded-xl p-6 mb-6">
                            <h3 class="text-2xl font-bold text-gray-800 mb-2">Partie terminée !</h3>
                            <p class="text-lg mb-4">Votre score final : <span id="finalScore" class="font-bold text-primary">0</span></p>
                            <button id="restartBtn" 
                                    class="bg-accent hover:bg-yellow-500 text-white px-6 py-3 rounded-lg font-medium transition duration-300">
                                <i class="fas fa-redo mr-2"></i>Rejouer
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Leaderboard -->
            <div class="bg-white rounded-2xl shadow-xl p-6">
                <h2 class="text-2xl font-bold text-center mb-6 text-gray-700">Top 10 Joueurs</h2>
                <div id="leaderboard" class="space-y-3">
                    <!-- Leaderboard items will be inserted here -->
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-trophy text-3xl mb-2"></i>
                        <p>Chargement du classement...</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Game Instructions -->
        <div class="mt-10 bg-white rounded-2xl shadow-xl p-6 max-w-4xl mx-auto">
            <h3 class="text-xl font-bold mb-4 text-gray-700">Comment jouer ?</h3>
            <ul class="grid grid-cols-1 md:grid-cols-3 gap-4">
                <li class="flex items-start">
                    <div class="bg-blue-100 rounded-full p-2 mr-3">
                        <i class="fas fa-user text-blue-500"></i>
                    </div>
                    <div>
                        <h4 class="font-semibold">1. Entrez votre pseudo</h4>
                        <p class="text-sm text-gray-600">Saisissez votre nom pour commencer</p>
                    </div>
                </li>
                <li class="flex items-start">
                    <div class="bg-green-100 rounded-full p-2 mr-3">
                        <i class="fas fa-keyboard text-green-500"></i>
                    </div>
                    <div>
                        <h4 class="font-semibold">2. Tapez les mots</h4>
                        <p class="text-sm text-gray-600">Tapez le mot affiché le plus rapidement possible</p>
                    </div>
                </li>
                <li class="flex items-start">
                    <div class="bg-purple-100 rounded-full p-2 mr-3">
                        <i class="fas fa-trophy text-purple-500"></i>
                    </div>
                    <div>
                        <h4 class="font-semibold">3. Battez des records</h4>
                        <p class="text-sm text-gray-600">Améliorez votre score et montez dans le classement</p>
                    </div>
                </li>
            </ul>
        </div>
    </div>

    <script>
        // Game state
        let gameState = {
            playerName: '',
            score: 0,
            wordCount: 0,
            timeLeft: 30,
            timer: null,
            gameActive: false,
            currentWord: ''
        };

        // DOM Elements
        const elements = {
            playerSetup: document.getElementById('playerSetup'),
            gameInterface: document.getElementById('gameInterface'),
            playerNameInput: document.getElementById('playerName'),
            startGameBtn: document.getElementById('startGameBtn'),
            timerDisplay: document.getElementById('timer'),
            scoreDisplay: document.getElementById('score'),
            wordCountDisplay: document.getElementById('wordCount'),
            currentWordDisplay: document.getElementById('currentWord'),
            typingInput: document.getElementById('typingInput'),
            gameOver: document.getElementById('gameOver'),
            finalScore: document.getElementById('finalScore'),
            restartBtn: document.getElementById('restartBtn'),
            leaderboard: document.getElementById('leaderboard'),
            progressBar: document.getElementById('progressBar'),
            progressText: document.getElementById('progressText')
        };

        // Initialize game
        function initGame() {
            // Event listeners
            elements.startGameBtn.addEventListener('click', startGame);
            elements.restartBtn.addEventListener('click', restartGame);
            elements.typingInput.addEventListener('input', checkInput);
            
            // Load leaderboard
            loadLeaderboard();
        }

        // Start the game
        function startGame() {
            const playerName = elements.playerNameInput.value.trim();
            if (!playerName) {
                alert('Veuillez entrer un pseudo');
                return;
            }
            
            gameState.playerName = playerName;
            elements.playerSetup.classList.add('hidden');
            elements.gameInterface.classList.remove('hidden');
            
            resetGame();
            startTimer();
            fetchNewWord();
            elements.typingInput.disabled = false;
            elements.typingInput.focus();
            gameState.gameActive = true;
        }

        // Reset game state
        function resetGame() {
            gameState.score = 0;
            gameState.wordCount = 0;
            gameState.timeLeft = 30;
            updateDisplays();
            elements.typingInput.value = '';
            elements.gameOver.classList.add('hidden');
            elements.progressBar.style.width = '0%';
            elements.progressText.textContent = '0%';
        }

        // Start the timer
        function startTimer() {
            clearInterval(gameState.timer);
            gameState.timer = setInterval(() => {
                gameState.timeLeft--;
                updateTimerDisplay();
                
                if (gameState.timeLeft <= 0) {
                    endGame();
                }
            }, 1000);
        }

        // Update all displays
        function updateDisplays() {
            elements.scoreDisplay.textContent = gameState.score;
            elements.wordCountDisplay.textContent = gameState.wordCount;
            updateTimerDisplay();
        }

        // Update timer display
        function updateTimerDisplay() {
            elements.timerDisplay.textContent = gameState.timeLeft;
            
            // Change color when time is running low
            if (gameState.timeLeft <= 10) {
                elements.timerDisplay.classList.add('text-red-500', 'pulse');
            } else {
                elements.timerDisplay.classList.remove('text-red-500', 'pulse');
            }
        }

        // Fetch a new word from the API
        function fetchNewWord() {
            // In a real implementation, this would call the API
            // For demo purposes, we'll use a local word list
            const words = [
                'clavier', 'ordinateur', 'taper', 'jeu', 'code', 
                'rapide', 'azerty', 'vitesse', 'react', 'dactylo',
                'internet', 'souris', 'ecran', 'programmation', 'developpement',
                'javascript', 'php', 'mysql', 'bootstrap', 'tailwind'
            ];
            
            const randomIndex = Math.floor(Math.random() * words.length);
            gameState.currentWord = words[randomIndex];
            elements.currentWordDisplay.textContent = gameState.currentWord;
            elements.currentWordDisplay.classList.remove('correct', 'incorrect');
        }

        // Check user input
        function checkInput() {
            if (!gameState.gameActive) return;
            
            const typedValue = elements.typingInput.value;
            
            // Visual feedback
            if (typedValue === gameState.currentWord) {
                elements.currentWordDisplay.classList.add('correct');
                elements.currentWordDisplay.classList.remove('incorrect');
            } else if (gameState.currentWord.startsWith(typedValue)) {
                elements.currentWordDisplay.classList.remove('correct', 'incorrect');
            } else {
                elements.currentWordDisplay.classList.add('incorrect');
                elements.currentWordDisplay.classList.remove('correct');
            }
            
            // Check if word is completed
            if (typedValue === gameState.currentWord) {
                // Update score and word count
                gameState.score += gameState.currentWord.length;
                gameState.wordCount++;
                
                // Update progress
                const progress = Math.min(100, (30 - gameState.timeLeft) * 3.33);
                elements.progressBar.style.width = `${progress}%`;
                elements.progressText.textContent = `${Math.round(progress)}%`;
                
                // Update displays
                updateDisplays();
                
                // Clear input and fetch new word
                elements.typingInput.value = '';
                fetchNewWord();
                
                // Add animation effect
                elements.currentWordDisplay.classList.add('pulse');
                setTimeout(() => {
                    elements.currentWordDisplay.classList.remove('pulse');
                }, 300);
            }
        }

        // End the game
        function endGame() {
            clearInterval(gameState.timer);
            gameState.gameActive = false;
            elements.typingInput.disabled = true;
            elements.finalScore.textContent = gameState.score;
            elements.gameOver.classList.remove('hidden');
            
            // Save score (in a real app, this would call the API)
            saveScore();
        }

        // Save score to leaderboard
        function saveScore() {
            // In a real implementation, this would send to the API
            // For demo, we'll just update the local leaderboard
            loadLeaderboard();
        }

        // Load leaderboard
        function loadLeaderboard() {
            // In a real implementation, this would fetch from the API
            // For demo, we'll use sample data
            const sampleScores = [
                { player: 'Alice', score: 245, played_at: '2023-06-15' },
                { player: 'Bob', score: 198, played_at: '2023-06-14' },
                { player: 'Charlie', score: 176, played_at: '2023-06-13' },
                { player: 'Diana', score: 165, played_at: '2023-06-12' },
                { player: 'Eve', score: 142, played_at: '2023-06-11' },
                { player: 'Frank', score: 130, played_at: '2023-06-10' },
                { player: 'Grace', score: 115, played_at: '2023-06-09' },
                { player: 'Henry', score: 98, played_at: '2023-06-08' },
                { player: 'Ivy', score: 87, played_at: '2023-06-07' },
                { player: 'Jack', score: 75, played_at: '2023-06-06' }
            ];
            
            renderLeaderboard(sampleScores);
            // Afficher le leaderboard après la partie
            document.getElementById('leaderboardSection').classList.remove('hidden');
        }

        // Render leaderboard
        function renderLeaderboard(scores) {
            elements.leaderboard.innerHTML = '';
            
            if (scores.length === 0) {
                elements.leaderboard.innerHTML = `
                    <div class="text-center py-8 text-gray-500">
                        <i class="fas fa-trophy text-3xl mb-2"></i>
                        <p>Aucun score enregistré</p>
                    </div>
                `;
                return;
            }
            
            scores.forEach((score, index) => {
                const position = index + 1;
                const medalClass = position <= 3 ? 
                    (position === 1 ? 'text-yellow-600' : 
                     position === 2 ? 'text-gray-600' : 
                     'text-red-600') : 'text-gray-500';
                
                const medalIcon = position <= 3 ? 
                    (position === 1 ? 'fa-trophy' : 
                     position === 2 ? 'fa-medal' : 
                     'fa-award') : '';
                
                elements.leaderboard.innerHTML += `
                    <div class="leaderboard-item flex items-center justify-between p-4 rounded-lg ${position <= 3 ? 'text-white' : 'bg-gray-50'}">
                        <div class="flex items-center">
                            <div class="w-8 h-8 flex items-center justify-center rounded-full ${position <= 3 ? '' : 'bg-gray-200'}">
                                <span class="font-bold ${position <= 3 ? 'text-white' : medalClass}">
                                    ${position}
                                </span>
                            </div>
                            <div class="ml-4">
                                <div class="font-semibold">${score.player}</div>
                                <div class="text-sm ${position <= 3 ? 'text-white/90' : 'text-gray-500'}">${score.played_at}</div>
                            </div>
                        </div>
                        <div class="flex items-center">
                            <span class="font-bold text-lg mr-2">${score.score}</span>
                            ${position <= 3 ? `<i class="fas ${medalIcon} ${medalClass}"></i>` : ''}
                        </div>
                    </div>
                `;
            });
        }

        // Restart the game
        function restartGame() {
            elements.playerSetup.classList.remove('hidden');
            elements.gameInterface.classList.add('hidden');
            elements.playerNameInput.value = gameState.playerName;
        }

        // Initialize when page loads
        document.addEventListener('DOMContentLoaded', 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=RebCode/azertype" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>