File size: 2,756 Bytes
9096441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

document.addEventListener('DOMContentLoaded', function() {
    const startGameBtn = document.getElementById('startGame');
    let gamePhase = 0;
    let candidates = [];
    let currentYear = 0;
    let gameData = {
        economicIndex: 50,
        socialIndex: 50,
        politicalIndex: 50,
        environmentIndex: 50
    };

    // Initialize game with default KPIs
    const initialKPIs = {
        pib: 1.5,
        dette: 112.5,
        emploi: 7.4,
        pouvoirAchat: 0.8,
        immigration: 230000,
        criminalite: 100,
        depensesPubliques: 56.4,
        balanceCommerciale: -43.2,
        satisfaction: 52,
        confianceIntern: 68
    };

    startGameBtn.addEventListener('click', function() {
        gamePhase = 1;
        const candidateNames = prompt('Entrez les prénoms des candidats (séparés par des virgules):');
        if (candidateNames) {
            candidates = candidateNames.split(',').map(name => name.trim());
            alert(`Candidats enregistrés: ${candidates.join(', ')}\n\nPassez maintenant à la phase 2: création des programmes.`);
            updateGameUI();
        }
    });

    function updateGameUI() {
        const dashboard = document.querySelector('custom-dashboard');
        if (dashboard) {
            dashboard.setAttribute('phase', gamePhase);
            dashboard.setAttribute('years', currentYear);
            
            if (gamePhase >= 2) {
                dashboard.setAttribute('candidates', JSON.stringify(candidates));
            }
        }
    }

    function simulateYear() {
        // Simulate economic, social and political changes
        gameData.economicIndex += (Math.random() * 10 - 5);
        gameData.socialIndex += (Math.random() * 10 - 5);
        gameData.politicalIndex += (Math.random() * 10 - 5);
        gameData.environmentIndex += (Math.random() * 10 - 5);
        
        currentYear++;
        updateGameUI();
        
        if (currentYear === 5) {
            showFinalResults();
        }
    }

    function showFinalResults() {
        // Calculate final scores
        const results = candidates.map(candidate => {
            return {
                name: candidate,
                score: Math.floor(Math.random() * 100)
            };
        }).sort((a, b) => b.score - a.score);

        const resultText = results.map(r => `${r.name}: ${r.score}%`).join('\n');
        alert(`Résultats finaux après 5 ans:\n\n${resultText}`);
    }

    // Expose functions for the game to be controlled by UI
    window.startNextPhase = function() {
        if (gamePhase < 9) {
            gamePhase++;
            if (gamePhase >= 3) {
                simulateYear();
            }
            updateGameUI();
        }
    };
});