refactor(game): simplify GameState construction and initialization

- Removed `GameStatus` dependency from `GameState` constructors.
- Adjusted `ClientGameState` and `ServerGameState` constructors accordingly.
- Simplified `ServerGameState::init()` to handle card initialization and player actions.
- Updated tests to reflect these changes.
This commit is contained in:
Kieran Kihn
2025-12-02 11:08:42 +08:00
parent a650b61610
commit e5304b8c6c
3 changed files with 12 additions and 18 deletions

View File

@@ -97,7 +97,7 @@ namespace UNO::GAME {
return this->handCard_.isEmpty();
}
ClientGameState::ClientGameState(GameStatus gameStatus, std::string name) : GameState(gameStatus), player_(std::move(name)) {}
ClientGameState::ClientGameState(std::string name) : player_(std::move(name)) {}
const std::multiset<Card> &ClientGameState::getCards() const
{
@@ -124,7 +124,7 @@ namespace UNO::GAME {
return this->player_.isEmpty();
}
ServerGameState::ServerGameState() : GameState(GameStatus::WAITING_PLAYERS_TO_JOIN) {}
ServerGameState::ServerGameState() = default;
void ServerGameState::init()
{
@@ -133,6 +133,12 @@ namespace UNO::GAME {
discardPile_.add(deck_.draw());
}
for (auto &player : this->players_) {
while (player.isEmpty() == false) {
player.play(*player.getCards().begin());
}
}
for (size_t i = 0; i < 7; i++) {
for (auto &player : this->players_) {
player.draw(1, this->deck_.draw(1));