From d8e6fef6bd261e6ce837098cc17425e2c4d8a5db Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Tue, 2 Dec 2025 15:13:09 +0800 Subject: [PATCH] Fix a bug about the switch component problem --- src/core/Game.cpp | 14 +++++++++----- src/core/Game.h | 2 +- src/core/GameTypes.h | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 9c3c8da..ec153bd 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -47,14 +47,14 @@ void Game::setPlayerAction(ActionType type) { } -void Game::executeAction(int toRow, int toCol) { +bool Game::executeAction(int toRow, int toCol) { auto [fromRow, fromCol] = *m_seletedPiece; if (m_currentActionType == ActionType::GROW) { if (Rule::canGrow(m_board.get(), fromRow, fromCol, toRow, toCol, m_currentPlayer)) { m_board->placePieceAt(toRow, toCol, m_currentPlayer); // 如果执行了操作就擦除 markComponentAsUsed(getOldComponentID(fromRow, fromCol)); - return; + return true; } } if (m_currentActionType == ActionType::MOVE) { @@ -64,7 +64,7 @@ void Game::executeAction(int toRow, int toCol) { m_board->placePieceAt(toRow, toCol, m_currentPlayer); markComponentAsUsed(getOldComponentID(fromRow, fromCol)); - return; + return true; } } if (m_currentActionType == ActionType::SPORE) { @@ -73,9 +73,10 @@ void Game::executeAction(int toRow, int toCol) { m_board->placePieceAt(toRow, toCol, m_currentPlayer); markComponentAsUsed(getOldComponentID(fromRow, fromCol)); - return; + return true; } } + return false; } @@ -156,7 +157,10 @@ bool Game::handleCoordinateInput(int row, int col) { //但是如果点击同一块 也无需处理,因为 在m_actionableComponents已经不存在了,直接尝试执行行动,但因为rule处理了所以不用管 // 其它情况则执行行动 - executeAction(row, col); + if(!executeAction(row, col)) { + std::cout << "action pos invaild!\n"; + return false; + } // 执行完之后检查是否m_actionableComponents为空, diff --git a/src/core/Game.h b/src/core/Game.h index 357fd62..c05537c 100644 --- a/src/core/Game.h +++ b/src/core/Game.h @@ -34,7 +34,7 @@ public: // 设置行动类型 void setPlayerAction(ActionType type); // 执行玩家的行动 - void executeAction(int row, int col); + bool executeAction(int row, int col); // 获取当前玩家 PlayerID getCurrentPlayer() const; // 打印棋盘 diff --git a/src/core/GameTypes.h b/src/core/GameTypes.h index 60da370..3c2adad 100644 --- a/src/core/GameTypes.h +++ b/src/core/GameTypes.h @@ -14,3 +14,20 @@ enum class ActionType { SPORE }; +enum class GameState { + MAIN_MENU, // 主菜单(开始界面) + SETTINGS, // 设置界面(音量、画质等) + GAME_SETUP, // 对局前的设置(选择模式、玩家类型等) + IN_GAME, // 正在对局中(核心逻辑运行) + PAUSED, // 游戏暂停(可返回菜单或继续) + GAME_OVER, // 对局结束(显示胜负/平局) + TUTORIAL, // 教程模式(可选) + EXITING // 退出确认或正在退出 +}; + +enum class GameMode { + LOCAL_PVP, // 本地两人对战 + VS_AI, // 玩家 vs AI + ONLINE_PVP, // 网络对战 + TUTORIAL_MODE // 教程(可视为特殊模式) +}; \ No newline at end of file