/
ivaninvv
/
minus-5
Обзор
Документация
Войти
/
ivaninvv
/
minus-5
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/scenes/MainMenuScene.ts
110 строк
3 KB
Vladimir Ivanin
линтер
13 дек 2025, 23:25
13 дек 2025, 23:25
da0f563
Код
Авторство
О чём код?
import { Text } from 'pixi.js'; import { Scene } from '../core/Scene'; import { Game } from '../core/Game'; import { GameScene } from './GameScene'; import { Button } from '../ui/Button'; import { NetworkManager } from '../network/NetworkManager'; export class MainMenuScene extends Scene { private game: Game; private network: NetworkManager; private statusText: Text; private buttons: Button[] = []; constructor(game: Game) { super(); this.game = game; this.network = new NetworkManager(); // Title const title = new Text({ text: 'Minus 5', style: { fill: 'white', fontSize: 48, fontWeight: 'bold' } }); title.anchor.set(0.5); title.x = window.innerWidth / 2; title.y = 100; this.addChild(title); // Status this.statusText = new Text({ text: '', style: { fill: 'yellow', fontSize: 16 } }); this.statusText.anchor.set(0.5); this.statusText.x = window.innerWidth / 2; this.statusText.y = 150; this.addChild(this.statusText); // Buttons const btnLocal = new Button('Local Game', () => this.startLocal()); this.addChild(btnLocal); this.buttons.push(btnLocal); const btnHost = new Button('Host Game', () => this.startHost()); this.addChild(btnHost); this.buttons.push(btnHost); const btnJoin = new Button('Join Game', () => this.startJoin()); this.addChild(btnJoin); this.buttons.push(btnJoin); const btnBot = new Button('VS Computer', () => this.startBot()); this.addChild(btnBot); this.buttons.push(btnBot); this.resize(window.innerWidth, window.innerHeight); } private startLocal() { this.game.sceneManager.goTo(new GameScene(this.game)); } private async startHost() { this.statusText.text = 'Generating ID...'; const id = await this.network.getMyId(); this.statusText.text = `ID: ${id} (Waiting for opponent...)`; // Allow user to copy console.log('Host ID:', id); window.prompt('Share this ID with your friend:', id); this.network.onConnected = () => { this.statusText.text = 'Connected! Starting...'; setTimeout(() => { this.game.sceneManager.goTo(new GameScene(this.game, this.network, true)); }, 1000); }; } private startJoin() { const id = window.prompt('Enter Host ID:'); if (id) { this.statusText.text = 'Connecting...'; this.network.connect(id); this.network.onConnected = () => { this.statusText.text = 'Connected! Starting...'; setTimeout(() => { this.game.sceneManager.goTo(new GameScene(this.game, this.network, false)); }, 1000); }; } } private startBot() { this.game.sceneManager.goTo(new GameScene(this.game, undefined, false, true)); } update(_delta: number): void {} resize(width: number, _height: number): void { this.children.forEach(c => { if (c instanceof Text && c.text === 'Minus 5') { c.x = width / 2; } if (c === this.statusText) { c.x = width / 2; } }); const startY = 200; const gap = 70; this.buttons.forEach((btn, i) => { btn.x = width / 2 - 100; btn.y = startY + i * gap; }); } }