refactor(game): encapsulate Player and ClientGameState state management

- Replaced public `Player::handCard` pointer with private `HandCard` member.
- Introduced `draw`, `play`, and `getCards` methods in `Player` and `ClientGameState`.
- Modified `ClientGameState` constructor to accept player name instead of `Player` object.
- Updated tests to reflect new `Player` and `ClientGameState` structure.
This commit is contained in:
Kieran Kihn
2025-11-18 17:15:07 +08:00
parent 23cd94e656
commit e78741bd9d
5 changed files with 118 additions and 12 deletions

View File

@@ -97,7 +97,32 @@ namespace UNO::GAME {
return this->handCard_.isEmpty();
}
ClientGameState::ClientGameState(GameStatus gameStatus, Player player) : GameState(gameStatus), player(std::move(player)) {}
ClientGameState::ClientGameState(GameStatus gameStatus, std::string name) : GameState(gameStatus), player_(std::move(name)) {}
const std::multiset<Card> &ClientGameState::getCards() const
{
return this->player_.getCards();
}
void ClientGameState::draw(const Card &card)
{
this->player_.draw(card);
}
void ClientGameState::draw(const std::vector<Card> &cards)
{
this->player_.draw(cards);
}
Card ClientGameState::play(const std::multiset<Card>::iterator &it)
{
return this->player_.play(it);
}
bool ClientGameState::isEmpty() const
{
return this->player_.isEmpty();
}
ServerGameState::ServerGameState() : GameState(GameStatus::WAITING_PLAYERS_TO_JOIN) {}