mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-06-28 16:35:55 +08:00
e395ea424b
App.tsx 添加 menu/game/replay 三页面路由切换,MainMenu 新增 onReplayStart 属性区分对局与回放入口。App.css 实现经典木纹 视觉风格(深棕底色、米黄文字、皮革纹理按钮),index.css 基础 重置。修复 tsconfig 中 erasableSyntaxOnly 无效选项并安装 @types/node。
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import LocalGameSetup from './LocalGameSetup';
|
|
import AiGameSetup from './AiGameSetup';
|
|
import OnlineSetup from './OnlineSetup';
|
|
import LoadReplay from './LoadReplay';
|
|
|
|
type View = 'main' | 'local' | 'ai' | 'online' | 'replay';
|
|
|
|
interface Props {
|
|
onGameStart: () => void;
|
|
onReplayStart: () => void;
|
|
}
|
|
|
|
export default function MainMenu({ onGameStart, onReplayStart }: Props) {
|
|
const { t } = useTranslation();
|
|
const [view, setView] = useState<View>('main');
|
|
|
|
if (view === 'local') return <LocalGameSetup onBack={() => setView('main')} onStart={onGameStart} />;
|
|
if (view === 'ai') return <AiGameSetup onBack={() => setView('main')} onStart={onGameStart} />;
|
|
if (view === 'online') return <OnlineSetup onBack={() => setView('main')} onStart={onGameStart} />;
|
|
if (view === 'replay') return <LoadReplay onBack={() => setView('main')} onStart={onReplayStart} />;
|
|
|
|
return (
|
|
<div className="main-menu">
|
|
<h1 className="menu-title">{t('app.title')}</h1>
|
|
<div className="menu-buttons">
|
|
<button onClick={() => setView('local')}>{t('menu.local_game')}</button>
|
|
<button onClick={() => setView('ai')}>{t('menu.ai_game')}</button>
|
|
<button onClick={() => setView('online')}>{t('menu.online_game')}</button>
|
|
<button onClick={() => setView('replay')}>{t('menu.load_replay')}</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|