251 lines
6.6 KiB
TypeScript
251 lines
6.6 KiB
TypeScript
"use client";
|
|
|
|
import { useChessGame } from "./hooks/useChessGame";
|
|
import ChessBoard from "./components/ChessBoard";
|
|
import GameControls from "./components/GameControls";
|
|
import GameStatus from "./components/GameStatus";
|
|
import { BOARD_WIDTH } from "./components/ChessBoard";
|
|
|
|
export default function Home() {
|
|
const {
|
|
pieces,
|
|
turn,
|
|
status,
|
|
winner,
|
|
selectedPieceId,
|
|
validMoves,
|
|
moveHistory,
|
|
gameMode,
|
|
difficulty,
|
|
lastMove,
|
|
isAIThinking,
|
|
gameStarted,
|
|
canUndo,
|
|
isPlaying,
|
|
handlePieceClick,
|
|
handleEmptyClick,
|
|
newGame,
|
|
undo,
|
|
surrender,
|
|
closeModal,
|
|
setGameMode,
|
|
setDifficulty,
|
|
startGame,
|
|
} = useChessGame();
|
|
|
|
return (
|
|
<div
|
|
style={{
|
|
minHeight: "100vh",
|
|
backgroundColor: "#f3f4f6",
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
alignItems: "center",
|
|
padding: "16px",
|
|
gap: "16px",
|
|
}}
|
|
>
|
|
{/* 标题 */}
|
|
<h1
|
|
style={{
|
|
fontSize: "24px",
|
|
fontWeight: "bold",
|
|
color: "#333",
|
|
marginBottom: "8px",
|
|
}}
|
|
>
|
|
中国象棋
|
|
</h1>
|
|
|
|
{/* 红方黑方身份提示 */}
|
|
<div
|
|
style={{
|
|
display: "flex",
|
|
gap: "24px",
|
|
padding: "10px 24px",
|
|
backgroundColor: "#ffffff",
|
|
borderRadius: "8px",
|
|
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
fontSize: "14px",
|
|
}}
|
|
>
|
|
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
|
<span
|
|
style={{
|
|
width: "12px",
|
|
height: "12px",
|
|
borderRadius: "50%",
|
|
backgroundColor: "#d80000",
|
|
display: "inline-block",
|
|
}}
|
|
/>
|
|
<span style={{ fontWeight: "bold", color: "#d80000" }}>
|
|
红方:{gameMode === "人vsA*" || gameMode === "人vsDeepseek" ? "玩家" : "A* AI"}
|
|
</span>
|
|
</div>
|
|
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
|
|
<span
|
|
style={{
|
|
width: "12px",
|
|
height: "12px",
|
|
borderRadius: "50%",
|
|
backgroundColor: "#111111",
|
|
display: "inline-block",
|
|
}}
|
|
/>
|
|
<span style={{ fontWeight: "bold", color: "#111111" }}>
|
|
黑方:{gameMode === "人vsA*" ? "A* AI" : gameMode === "人vsDeepseek" ? "Deepseek AI" : "Deepseek AI"}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* AI思考提示 */}
|
|
{isAIThinking && (
|
|
<div
|
|
style={{
|
|
padding: "6px 16px",
|
|
backgroundColor: "#fef3c7",
|
|
borderRadius: "6px",
|
|
color: "#92400e",
|
|
fontSize: "14px",
|
|
fontWeight: 500,
|
|
}}
|
|
>
|
|
AI思考中...
|
|
</div>
|
|
)}
|
|
|
|
{/* 棋盘区域 */}
|
|
<div style={{ position: "relative" }}>
|
|
{/* 开始按钮遮罩 */}
|
|
{!gameStarted && (
|
|
<div
|
|
style={{
|
|
position: "absolute",
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
backgroundColor: "rgba(0,0,0,0.6)",
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
borderRadius: "8px",
|
|
zIndex: 20,
|
|
gap: "16px",
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
fontSize: "20px",
|
|
color: "white",
|
|
fontWeight: "bold",
|
|
textAlign: "center",
|
|
}}
|
|
>
|
|
准备开始棋局
|
|
</div>
|
|
<button
|
|
onClick={() => {
|
|
console.log("[Chess] Button clicked!");
|
|
startGame();
|
|
}}
|
|
style={{
|
|
padding: "16px 48px",
|
|
borderRadius: "8px",
|
|
border: "none",
|
|
backgroundColor: "#16a34a",
|
|
color: "white",
|
|
fontSize: "20px",
|
|
fontWeight: "bold",
|
|
cursor: "pointer",
|
|
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
transition: "all 0.2s",
|
|
}}
|
|
onMouseEnter={(e) => {
|
|
e.currentTarget.style.backgroundColor = "#15803d";
|
|
e.currentTarget.style.transform = "scale(1.05)";
|
|
}}
|
|
onMouseLeave={(e) => {
|
|
e.currentTarget.style.backgroundColor = "#16a34a";
|
|
e.currentTarget.style.transform = "scale(1)";
|
|
}}
|
|
>
|
|
开始
|
|
</button>
|
|
<div
|
|
style={{
|
|
fontSize: "14px",
|
|
color: "rgba(255,255,255,0.8)",
|
|
textAlign: "center",
|
|
}}
|
|
>
|
|
当前模式:{gameMode} | 难度:{difficulty}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* 棋盘 */}
|
|
<div style={{ opacity: gameStarted ? 1 : 0.5 }}>
|
|
<ChessBoard
|
|
pieces={pieces}
|
|
selectedPieceId={selectedPieceId}
|
|
validMoves={validMoves}
|
|
lastMove={lastMove}
|
|
onPieceClick={handlePieceClick}
|
|
onEmptyClick={handleEmptyClick}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 游戏状态和走棋记录 */}
|
|
<div style={{ width: `${BOARD_WIDTH}px`, maxWidth: "100%" }}>
|
|
<GameStatus
|
|
status={status}
|
|
turn={turn}
|
|
winner={winner}
|
|
moveHistory={moveHistory}
|
|
onCloseModal={closeModal}
|
|
/>
|
|
</div>
|
|
|
|
{/* 游戏控制 */}
|
|
<div style={{ width: `${BOARD_WIDTH}px`, maxWidth: "100%" }}>
|
|
<GameControls
|
|
mode={gameMode}
|
|
difficulty={difficulty}
|
|
onModeChange={setGameMode}
|
|
onDifficultyChange={setDifficulty}
|
|
onNewGame={newGame}
|
|
onUndo={undo}
|
|
onSurrender={surrender}
|
|
canUndo={canUndo}
|
|
isPlaying={isPlaying}
|
|
/>
|
|
</div>
|
|
|
|
|
|
|
|
{/* 底部说明 */}
|
|
<div
|
|
style={{
|
|
marginTop: "8px",
|
|
padding: "10px",
|
|
backgroundColor: "#ffffff",
|
|
borderRadius: "8px",
|
|
boxShadow: "0 2px 8px rgba(0,0,0,0.1)",
|
|
fontSize: "12px",
|
|
color: "#666",
|
|
textAlign: "center",
|
|
maxWidth: `${BOARD_WIDTH}px`,
|
|
}}
|
|
>
|
|
<p>点击己方棋子选中,再点击目标位置移动</p>
|
|
<p style={{ marginTop: "4px" }}>
|
|
支持人vsA*、人vsDeepseek、A*vsDeepseek三种模式
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |