Fix a bug about the switch component problem

This commit is contained in:
2025-12-02 15:13:09 +08:00
parent 06b840e7ff
commit d8e6fef6bd
3 changed files with 27 additions and 6 deletions

View File

@@ -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为空

View File

@@ -34,7 +34,7 @@ public:
// 设置行动类型
void setPlayerAction(ActionType type);
// 执行玩家的行动
void executeAction(int row, int col);
bool executeAction(int row, int col);
// 获取当前玩家
PlayerID getCurrentPlayer() const;
// 打印棋盘

View File

@@ -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 // 教程(可视为特殊模式)
};