mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-06-29 00:45:55 +08:00
feat(frontend): 菜单组件 — 主菜单/本地双人/AI设置/网络/加载棋谱
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
|
||||
export default function MainMenu({ onGameStart }: 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={onGameStart} />;
|
||||
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user