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