Spaces:
Running
Running
| 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(); | |
| } | |
| }; | |
| }); | |