From 56a900686dbbb9bbe326d5eb656306fcb3776814 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Thu, 5 Feb 2026 16:28:21 +0800 Subject: [PATCH] balance: adjust values for GROW, MOVE, and SPORE --- src/game/Board.cpp | 9 +++++++++ src/game/Board.h | 2 ++ src/game/GameSession.cpp | 28 ++++++++++++++++++++++++++-- src/game/GameSession.h | 2 +- src/game/Piece.cpp | 3 ++- src/game/Piece.h | 27 +++++++++++++++++++++------ 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/game/Board.cpp b/src/game/Board.cpp index fc42e93..d584689 100644 --- a/src/game/Board.cpp +++ b/src/game/Board.cpp @@ -213,4 +213,13 @@ bool Board::changeATK(int row, int col, int num) { } m_grid[pieceID]->changeATK(num); return true; +} + +bool Board::setPieceInfo(int row, int col, PieceInfo pieceInfo) { + int pieceID = getPieceID(row, col); + if (!m_grid[pieceID]) { + return false; + } + m_grid[pieceID]->setInfo(pieceInfo); + return true; } \ No newline at end of file diff --git a/src/game/Board.h b/src/game/Board.h index b5d05c5..37cabaf 100644 --- a/src/game/Board.h +++ b/src/game/Board.h @@ -57,4 +57,6 @@ public: bool changeHP(int row, int col, int num); bool changeATK(int row, int col, int num); + + bool setPieceInfo(int row, int col, PieceInfo pieceInfo); }; \ No newline at end of file diff --git a/src/game/GameSession.cpp b/src/game/GameSession.cpp index d09b6fa..550f649 100644 --- a/src/game/GameSession.cpp +++ b/src/game/GameSession.cpp @@ -61,10 +61,23 @@ bool GameSession::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)) { - + auto fromPiece = m_board->getPieceAt(fromRow, fromCol); + auto toPiece = m_board->getPieceAt(toRow, toCol); + auto fromInfo = fromPiece->getPieceInfo(); + if (fromInfo.HP / 2 == 0) { + // 因为每个玩家结束全部棋子恢复2HP,所以理论来说是不可能GROW死的 + m_gamePieceEventCallback(GamePieceEvent::REMOVE_PIECE, fromRow, fromCol, -1, -1); + m_board->removePieceAt(fromRow, fromCol); + markComponentAsUsed(getOldComponentID(fromRow, fromCol)); + return true; + } + fromInfo.HP /= 2; + fromInfo.ATK += 2; m_gamePieceEventCallback(GamePieceEvent::PLACE_PIECE, toRow, toCol, -1, -1); m_gamePieceEventCallback(GamePieceEvent::GROW_PIECE, fromRow, fromCol, toRow, toCol); m_board->placePieceAt(toRow, toCol, m_currentPlayer); + m_board->setPieceInfo(fromRow, fromCol, fromInfo); + m_board->setPieceInfo(toRow, toCol, fromInfo); // 如果执行了操作就擦除 markComponentAsUsed(getOldComponentID(fromRow, fromCol)); @@ -86,8 +99,11 @@ bool GameSession::executeAction(int toRow, int toCol) { if (!toPiece) { m_gamePieceEventCallback(GamePieceEvent::MOVE_PIECE, fromRow, fromCol, toRow, toCol); + auto fromInfo = fromPiece->getPieceInfo(); m_board->removePieceAt(fromRow, fromCol); m_board->placePieceAt(toRow, toCol, m_currentPlayer); + m_board->setPieceInfo(toRow, toCol, fromInfo); + //m_board->changeHP(toRow, toCol, -5); markComponentAsUsed(getOldComponentID(fromRow, fromCol)); return true; } @@ -105,8 +121,11 @@ bool GameSession::executeAction(int toRow, int toCol) { if (fromPiece->getHP() > 0) { m_gamePieceEventCallback(GamePieceEvent::MOVE_PIECE, fromRow, fromCol, toRow, toCol); + auto fromInfo = fromPiece->getPieceInfo(); m_board->removePieceAt(fromRow, fromCol); + m_board->placePieceAt(toRow, toCol, m_currentPlayer); + m_board->setPieceInfo(toRow, toCol, fromInfo); } } @@ -121,9 +140,14 @@ bool GameSession::executeAction(int toRow, int toCol) { m_gamePieceEventCallback(GamePieceEvent::REMOVE_PIECE, fromRow, fromCol, -1, -1); m_gamePieceEventCallback(GamePieceEvent::PLACE_PIECE, toRow, toCol, -1, -1); m_gamePieceEventCallback(GamePieceEvent::MOVE_PIECE, fromRow, fromCol, toRow, toCol); + + auto fromPiece = m_board->getPieceAt(fromRow, fromCol); + auto toPiece = m_board->getPieceAt(toRow, toCol); + auto fromInfo = fromPiece->getPieceInfo(); m_board->removePieceAt(fromRow, fromCol); m_board->placePieceAt(toRow, toCol, m_currentPlayer); - + m_board->setPieceInfo(toRow, toCol, fromInfo); + m_board->changeHP(toRow, toCol, -2); markComponentAsUsed(getOldComponentID(fromRow, fromCol)); return true; } diff --git a/src/game/GameSession.h b/src/game/GameSession.h index a3d9b5a..e194cab 100644 --- a/src/game/GameSession.h +++ b/src/game/GameSession.h @@ -75,5 +75,5 @@ public: } PieceInfo getPieceInfo(int row, int col) const; - + }; \ No newline at end of file diff --git a/src/game/Piece.cpp b/src/game/Piece.cpp index f2e06e1..c5b3855 100644 --- a/src/game/Piece.cpp +++ b/src/game/Piece.cpp @@ -1,7 +1,8 @@ #include "Piece.h" Piece::Piece(PlayerID ID) : m_owner(ID) { - + m_pieceInfo.ATK = 10; + m_pieceInfo.HP = 20; } Piece::~Piece() { diff --git a/src/game/Piece.h b/src/game/Piece.h index cb5dbb8..e9bb1ac 100644 --- a/src/game/Piece.h +++ b/src/game/Piece.h @@ -5,24 +5,39 @@ class Piece { private: PlayerID m_owner; - int HP = 20; - int ATK = 10; + PieceInfo m_pieceInfo; + public: Piece(PlayerID ID); ~Piece(); PlayerID getPieceOwner() const; void changeHP(int num) { - HP += num; + m_pieceInfo.HP += num; } void changeATK(int num) { - ATK += num; + m_pieceInfo.ATK += num; } int getHP() const { - return HP; + return m_pieceInfo.HP; } int getATK() const { - return ATK; + return m_pieceInfo.ATK; + } + PieceInfo getPieceInfo() const { + return m_pieceInfo; + } + + void setHP(int HP) { + m_pieceInfo.HP = HP; + } + + void setATK(int ATK) { + m_pieceInfo.ATK = ATK; + } + + void setInfo(PieceInfo pieceInfo) { + m_pieceInfo = pieceInfo; } }; \ No newline at end of file