File size: 3,736 Bytes
001d03c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
document.addEventListener('DOMContentLoaded', function() {
    // Initialize match history from localStorage or create empty array
    let matchHistory = JSON.parse(localStorage.getItem('stadiumModHistory')) || [];
    
    // Set next match date (always next Saturday)
    const today = new Date();
    const nextSaturday = new Date(today);
    nextSaturday.setDate(today.getDate() + (6 - today.getDay() + 7) % 7);
    document.getElementById('next-match').textContent = nextSaturday.toLocaleDateString('en-US', { 
        weekday: 'long', 
        month: 'long', 
        day: 'numeric' 
    });

    // Display match history
    renderMatchHistory();

    // Simulation button
    document.getElementById('simulate-btn').addEventListener('click', function() {
        simulateMatch();
    });

    function simulateMatch() {
        const resultContainer = document.getElementById('result-container');
        const matchResult = document.getElementById('match-result');
        const happinessImpact = document.getElementById('happiness-impact');
        
        // Random result (60% chance to win, 40% to lose)
        const isWin = Math.random() < 0.6;
        const resultText = isWin ? "๐Ÿ† Your team won!" : "๐Ÿ˜ž Your team lost...";
        const impactText = isWin ? 
            "Citizens are celebrating! Happiness increased by 15%." : 
            "Citizens are disappointed. Happiness decreased by 10%.";
        
        // Add to match history
        const matchEntry = {
            date: new Date().toLocaleDateString(),
            result: isWin ? 'win' : 'loss',
            happinessChange: isWin ? 15 : -10
        };
        
        matchHistory.unshift(matchEntry);
        localStorage.setItem('stadiumModHistory', JSON.stringify(matchHistory));
        
        // Display result
        matchResult.textContent = resultText;
        happinessImpact.textContent = impactText;
        resultContainer.className = isWin ? 
            'mt-4 p-4 rounded-lg win-animation' : 
            'mt-4 p-4 rounded-lg loss-animation';
        resultContainer.classList.remove('hidden');
        
        // Update history display
        renderMatchHistory();
        
        // Disable button temporarily
        const btn = document.getElementById('simulate-btn');
        btn.disabled = true;
        setTimeout(() => {
            btn.disabled = false;
        }, 3000);
    }

    function renderMatchHistory() {
        const container = document.getElementById('match-history');
        container.innerHTML = '';
        
        if (matchHistory.length === 0) {
            container.innerHTML = '<p class="text-gray-500">No matches played yet</p>';
            return;
        }
        
        matchHistory.forEach(match => {
            const matchEl = document.createElement('div');
            matchEl.className = `match-item p-3 rounded-lg flex justify-between items-center ${
                match.result === 'win' ? 'bg-green-50' : 'bg-red-50'
            }`;
            
            matchEl.innerHTML = `
                <div class="flex items-center">
                    <i data-feather="${match.result === 'win' ? 'thumbs-up' : 'thumbs-down'}" 
                       class="w-4 h-4 mr-2 ${match.result === 'win' ? 'text-green-500' : 'text-red-500'}"></i>
                    <span class="font-medium">${match.date}</span>
                </div>
                <span class="${match.result === 'win' ? 'text-green-600' : 'text-red-600'} font-bold">
                    ${match.result === 'win' ? '+' : ''}${match.happinessChange}% happiness
                </span>
            `;
            
            container.appendChild(matchEl);
        });
        
        feather.replace();
    }
});