This commit is contained in:
2026-02-02 19:18:25 +03:00
commit 038b307d70
21 changed files with 4987 additions and 0 deletions

129
static/js/game.js Normal file
View File

@@ -0,0 +1,129 @@
// Логика игрового процесса
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();
});
}

87
static/js/main.js Normal file
View File

@@ -0,0 +1,87 @@
// Общие функции для всех страниц
// Инициализация табов
function initTabs() {
const tabs = document.querySelectorAll('.tab');
if (tabs.length > 0) {
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const tabId = this.getAttribute('data-tab');
if (tabId) {
switchTab(tabId);
}
});
});
}
}
function switchTab(tabId) {
// Удаляем активный класс у всех вкладок
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
// Добавляем активный класс выбранной вкладке
const activeTab = document.querySelector(`.tab[data-tab="${tabId}"]`);
const activeContent = document.getElementById(`${tabId}-tab`);
if (activeTab) activeTab.classList.add('active');
if (activeContent) activeContent.classList.add('active');
}
// Таймер обратного отсчета
class GameTimer {
constructor(elementId, duration) {
this.element = document.getElementById(elementId);
this.duration = duration;
this.timeLeft = duration;
this.interval = null;
}
start() {
this.updateDisplay();
this.interval = setInterval(() => {
this.timeLeft--;
this.updateDisplay();
if (this.timeLeft <= 0) {
this.stop();
if (this.onComplete) this.onComplete();
}
}, 1000);
}
stop() {
if (this.interval) {
clearInterval(this.interval);
this.interval = null;
}
}
updateDisplay() {
if (this.element) {
const minutes = Math.floor(this.timeLeft / 60);
const seconds = this.timeLeft % 60;
this.element.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}
}
}
// Форматирование чисел (валюты)
function formatCurrency(amount) {
return new Intl.NumberFormat('ru-RU', {
style: 'currency',
currency: 'RUB',
minimumFractionDigits: 0
}).format(amount);
}
// Инициализация при загрузке страницы
document.addEventListener('DOMContentLoaded', function() {
initTabs();
// Инициализация текущего пользователя
const currentUser = localStorage.getItem('currentUser');
if (currentUser && document.getElementById('current-user')) {
document.getElementById('current-user').textContent = currentUser;
}
});