mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
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:
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user