feat(game): add player name management methods

- Added `setPlayerName` and `getPlayerName` to `ClientGameState`.
- Introduced `setName` method for `Player`.
- Updated constructors for `Player` and `ClientGameState` to support name management.
This commit is contained in:
Kieran Kihn
2025-12-09 19:43:51 +08:00
parent 3b31dd2dcc
commit 5eee316acf
4 changed files with 33 additions and 6 deletions

View File

@@ -95,7 +95,18 @@ namespace UNO::GAME {
this->handCard_.clear();
}
ClientGameState::ClientGameState(std::string name) : player_(std::move(name)), clientGameStage_(ClientGameStage::PENDING_CONNECTION) {}
ClientGameState::ClientGameState() : clientGameStage_(ClientGameStage::PENDING_CONNECTION) {}
std::string ClientGameState::getPlayerName() const
{
return this->player_.getName();
}
void ClientGameState::setPlayerName(const std::string &name)
{
this->player_.setName(name);
}
void ClientGameState::nextPlayer()
{
@@ -108,7 +119,6 @@ namespace UNO::GAME {
}
}
const std::multiset<Card> &ClientGameState::getCards() const
{
return this->player_.getCards();
@@ -133,7 +143,6 @@ namespace UNO::GAME {
}
}
void ClientGameState::draw(const Card &card)
{
this->player_.draw(card);

View File

@@ -316,7 +316,17 @@ namespace UNO::GAME {
void nextPlayer() override;
public:
explicit ClientGameState(std::string name);
ClientGameState();
/**
* 设置玩家名字
*/
void setPlayerName(const std::string &name);
/**
* 获取当前玩家的名字
* @return 玩家名字
*/
[[nodiscard]] std::string getPlayerName() const;
/**
* 获得当前手牌

View File

@@ -59,13 +59,19 @@ namespace UNO::GAME {
this->cards_.clear();
}
Player::Player(std::string name) : name_(std::move(name)) {}
Player::Player() = default;
const std::string &Player::getName() const
{
return this->name_;
}
void Player::setName(const std::string &name)
{
this->name_ = name;
}
const std::multiset<Card> &Player::getCards() const
{
return this->handCard_.getCards();

View File

@@ -75,13 +75,15 @@ namespace UNO::GAME {
HandCard handCard_;
public:
explicit Player(std::string name);
Player();
/**
* @return 返回玩家名字
*/
[[nodiscard]] const std::string &getName() const;
void setName(const std::string &name);
/**
* 获得当前手牌
* @return 当前手牌的集合