// Логика игрового процесса class Game { constructor() { this.month = 1; this.phase = 'action'; // action, market, event, results this.playerCapital = 100000; this.assets = []; this.abilities = []; } init() { this.loadGameState(); this.startPhaseTimer(); this.updateUI(); } startPhaseTimer() { const phaseDurations = { action: 120, // 2 минуты market: 30, // 30 секунд event: 30, // 30 секунд results: 45 // 45 секунд }; this.timer = new GameTimer('phase-timer', phaseDurations[this.phase]); this.timer.onComplete = () => this.nextPhase(); this.timer.start(); } nextPhase() { const phases = ['action', 'market', 'event', 'results']; const currentIndex = phases.indexOf(this.phase); const nextIndex = (currentIndex + 1) % phases.length; this.phase = phases[nextIndex]; if (this.phase === 'results') { this.endMonth(); } this.updatePhaseDisplay(); this.startPhaseTimer(); } endMonth() { this.month++; this.calculateMarketChanges(); this.applyRandomEvents(); this.updateLeaderboard(); if (this.month > 12) { this.endGame(); } } updateUI() { document.getElementById('game-month').textContent = `Месяц ${this.month}`; document.getElementById('player-capital').textContent = formatCurrency(this.playerCapital); // Обновление прогресс-бара const progress = (this.playerCapital / 500000) * 100; // Пример: цель 500к document.getElementById('capital-progress').style.width = Math.min(progress, 100) + '%'; } updatePhaseDisplay() { const phaseNames = { action: 'Фаза действий', market: 'Реакция рынка', event: 'Случайные события', results: 'Итоги месяца' }; document.getElementById('phase-timer').textContent = phaseNames[this.phase]; } calculateMarketChanges() { // Здесь будет сложная логика из концепции игры console.log('Расчет изменений рынка...'); } applyRandomEvents() { // Применение случайных и политических событий console.log('Применение событий...'); } updateLeaderboard() { // Обновление таблицы лидеров console.log('Обновление лидерборда...'); } endGame() { alert('Игра завершена! Победитель: ...'); window.location.href = 'rooms.html'; } loadGameState() { // Загрузка состояния игры из localStorage или сервера const saved = localStorage.getItem('gameState'); if (saved) { const state = JSON.parse(saved); Object.assign(this, state); } } saveGameState() { localStorage.setItem('gameState', JSON.stringify({ month: this.month, phase: this.phase, playerCapital: this.playerCapital, assets: this.assets, abilities: this.abilities })); } } // Инициализация игры function initGame() { window.game = new Game(); game.init(); // Автосохранение каждые 30 секунд setInterval(() => game.saveGameState(), 30000); // Обработка завершения хода document.getElementById('end-turn')?.addEventListener('click', () => { game.nextPhase(); }); }