Changed around line 0
- // Constants
- const REFERENCE_DATE = new Date('2024-12-01');
- const GAMES = {
- lol: 'League of Legends',
- csgo: 'CS:GO',
- fifa: 'FIFA',
- valorant: 'Valorant'
- };
-
- // State
- let currentGame = 'lol';
- let dailyPlayer = null;
- let guesses = [];
- let stats = {
- currentStreak: 0,
- maxStreak: 0,
- totalCorrect: 0,
- averageGuesses: 0,
- history: []
- };
-
- // DOM Elements
- const gameButtons = document.querySelectorAll('.game-icons button');
- const guessInput = document.getElementById('player-guess');
- const autocompleteDropdown = document.getElementById('autocomplete-dropdown');
- const guessResults = document.getElementById('guess-results');
- const statsModal = document.getElementById('stats-modal');
- const winModal = document.getElementById('win-modal');
- const themeToggle = document.getElementById('theme-toggle');
-
- // Initialize
- document.addEventListener('DOMContentLoaded', () => {
- loadGame(currentGame);
- setupEventListeners();
- updateCountdown();
- loadStats();
- });
-
- function setupEventListeners() {
- gameButtons.forEach(button => {
- button.addEventListener('click', () => switchGame(button.id));
- });
-
- guessInput.addEventListener('input', handleGuessInput);
- document.getElementById('stats-btn').addEventListener('click', showStats);
- document.querySelectorAll('.close').forEach(btn => {
- btn.addEventListener('click', () => {
- statsModal.style.display = 'none';
- winModal.style.display = 'none';
- });
- });
- themeToggle.addEventListener('click', toggleTheme);
- }
-
- function loadGame(game) {
- currentGame = game;
- dailyPlayer = getDailyPlayer(game);
- updateGameUI();
- }
-
- function getDailyPlayer(game) {
- const players = getPlayersForGame(game);
- const dayIndex = Math.floor((new Date() - REFERENCE_DATE) / (1000 * 60 * 60 * 24));
- return players[dayIndex % players.length];
- }
-
- function handleGuessInput() {
- const input = guessInput.value.toLowerCase();
- const players = getPlayersForGame(currentGame);
- const filtered = players.filter(p =>
- p.nickname.toLowerCase().includes(input) &&
- !guesses.includes(p.nickname)
- );
- showAutocomplete(filtered);
- }
-
- function showAutocomplete(players) {
- autocompleteDropdown.innerHTML = players
- .map(p => `
${p.nickname}
`)
- .join('');
- autocompleteDropdown.style.display = players.length ? 'block' : 'none';
- }
-
- function submitGuess(nickname) {
- const player = getPlayersForGame(currentGame).find(p => p.nickname === nickname);
- guesses.push(nickname);
- displayGuessResult(player);
- if (player.nickname === dailyPlayer.nickname) {
- handleWin();
- }
- }
-
- function displayGuessResult(player) {
- const row = document.createElement('div');
- row.className = 'guess-row';
- const attributes = ['nickname', 'team', 'nationality', 'role', 'age'];
- attributes.forEach(attr => {
- const tile = document.createElement('div');
- tile.className = 'guess-tile';
- tile.textContent = player[attr];
- if (player[attr] === dailyPlayer[attr]) {
- tile.classList.add('correct');
- } else {
- tile.classList.add('incorrect');
- if (typeof player[attr] === 'number') {
- tile.classList.add('arrow');
- tile.classList.add(player[attr] > dailyPlayer[attr] ? 'down' : 'up');
- }
- }
- row.appendChild(tile);
- });
- guessResults.appendChild(row);
- }
-
- function handleWin() {
- updateStats();
- showWinModal();
- }
-
- function updateStats() {
- stats.currentStreak++;
- stats.maxStreak = Math.max(stats.maxStreak, stats.currentStreak);
- stats.totalCorrect++;
- stats.averageGuesses = ((stats.averageGuesses * (stats.totalCorrect - 1)) + guesses.length) / stats.totalCorrect;
- stats.history.push({ date: new Date(), guesses: guesses.length });
- saveStats();
- }
-
- function showStats() {
- document.getElementById('current-streak').textContent = stats.currentStreak;
- document.getElementById('max-streak').textContent = stats.maxStreak;
- document.getElementById('average-guesses').textContent = stats.averageGuesses.toFixed(1);
- document.getElementById('total-correct').textContent = stats.totalCorrect;
- statsModal.style.display = 'block';
- }
-
- function showWinModal() {
- document.getElementById('win-guesses').textContent = guesses.length;
- winModal.style.display = 'block';
- }
-
- function toggleTheme() {
- const isDark = document.body.getAttribute('data-theme') === 'dark';
- document.body.setAttribute('data-theme', isDark ? 'light' : 'dark');
- themeToggle.textContent = isDark ? '🌞' : '🌙';
- }
-
- function updateCountdown() {
- const now = new Date();
- const midnight = new Date(now);
- midnight.setHours(24, 0, 0, 0);
- const diff = midnight - now;
- const hours = Math.floor(diff / (1000 * 60 * 60));
- const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
- const seconds = Math.floor((diff % (1000 * 60)) / 1000);
- document.getElementById('countdown-timer').textContent =
- `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
- setTimeout(updateCountdown, 1000);
- }
-
- // Placeholder functions - to be implemented
- function getPlayersForGame(game) {
- // Return array of players for the given game
- return [];
- }
-
- function loadStats() {
- // Load stats from localStorage
- }
-
- function saveStats() {
- // Save stats to localStorage
- }
-
- function updateGameUI() {
- // Update UI when switching games
- }