"use client"; import { Color, GameStatus as GameStatusType, Move } from "../types/chess"; interface GameStatusProps { status: GameStatusType; turn: Color; winner?: Color; moveHistory: Move[]; onCloseModal?: () => void; } export default function GameStatus({ status, turn, winner, moveHistory, onCloseModal, }: GameStatusProps) { const getStatusMessage = () => { switch (status) { case "playing": return `${turn === "red" ? "红方" : "黑方"}走棋`; case "check": return `${turn === "red" ? "红方" : "黑方"}被将军!`; case "checkmate": return `${winner === "red" ? "红方" : "黑方"}获胜!`; case "stalemate": case "draw": return "和棋"; default: return ""; } }; const getStatusColor = () => { switch (status) { case "playing": return "#2563eb"; case "check": return "#dc2626"; case "checkmate": return "#16a34a"; case "stalemate": case "draw": return "#6b7280"; default: return "#2563eb"; } }; // 只显示最近10步 const recentMoves = moveHistory.slice(-10); return ( <> {/* 状态显示 */}
{getStatusMessage()}
{status === "check" && (
请应将!
)}
{/* 走棋记录 */}
走棋记录
{moveHistory.length === 0 ? (
暂无走棋记录
) : (
{recentMoves.map((move, index) => { const moveNumber = Math.floor((moveHistory.length - recentMoves.length + index) / 2) + 1; const isRedMove = (moveHistory.length - recentMoves.length + index) % 2 === 0; return (
{isRedMove ? `${moveNumber}. ` : ""} {move.notation}
); })}
)}
{/* 游戏结束弹窗 */} {(status === "checkmate" || status === "stalemate" || status === "draw") && (
e.stopPropagation()} >
{status === "checkmate" ? `${winner === "red" ? "红方" : "黑方"}获胜!` : "和棋"}
{status === "checkmate" ? "恭喜取得胜利!" : "双方势均力敌,不分胜负"}
)} ); }