refactor(game): return drawn cards in updateStateByDraw

- Updated `updateStateByDraw` to return a `std::vector<Card>` instead of `void`.
- Adjusted `ServerGameState`, `GameState`, and `ClientGameState` implementations to reflect the change.
This commit is contained in:
Kieran Kihn
2025-12-02 12:06:06 +08:00
parent e5304b8c6c
commit 8a00b66047
2 changed files with 9 additions and 6 deletions

View File

@@ -146,13 +146,15 @@ namespace UNO::GAME {
}
}
void ServerGameState::updateStateByDraw()
std::vector<Card> ServerGameState::updateStateByDraw()
{
if (this->drawCount_ == 0) {
this->drawCount_ = 1;
}
this->currentPlayer_->draw(this->drawCount_, deck_.draw(this->drawCount_));
auto cards = deck_.draw(this->drawCount_);
this->currentPlayer_->draw(this->drawCount_, cards);
this->drawCount_ = 0;
this->nextPlayer();
return cards;
}
} // namespace UNO::GAME

View File

@@ -193,7 +193,7 @@ namespace UNO::GAME {
/**
* 由于用户摸牌而改变状态
*/
void virtual updateStateByDraw();
std::vector<Card> virtual updateStateByDraw();
};
template<PlayerStateTypeConcept PlayerStateType>
@@ -294,7 +294,7 @@ namespace UNO::GAME {
}
template<PlayerStateTypeConcept PlayerStateType>
void GameState<PlayerStateType>::updateStateByDraw()
std::vector<Card> GameState<PlayerStateType>::updateStateByDraw()
{
if (this->drawCount_ == 0) {
this->drawCount_ = 1;
@@ -302,6 +302,7 @@ namespace UNO::GAME {
this->currentPlayer_->draw(this->drawCount_, {});
this->drawCount_ = 0;
this->nextPlayer();
return {};
}
class ClientGameState final : public GameState<ClientPlayerState> {
@@ -309,7 +310,7 @@ namespace UNO::GAME {
Player player_;
public:
ClientGameState(std::string name);
explicit ClientGameState(std::string name);
/**
* 获得当前手牌
@@ -357,7 +358,7 @@ namespace UNO::GAME {
/**
* 由于用户摸牌而改变状态
*/
void updateStateByDraw() override;
std::vector<Card> updateStateByDraw() override;
};
} // namespace UNO::GAME