mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
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:
@@ -95,7 +95,18 @@ namespace UNO::GAME {
|
|||||||
this->handCard_.clear();
|
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()
|
void ClientGameState::nextPlayer()
|
||||||
{
|
{
|
||||||
@@ -108,7 +119,6 @@ namespace UNO::GAME {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::multiset<Card> &ClientGameState::getCards() const
|
const std::multiset<Card> &ClientGameState::getCards() const
|
||||||
{
|
{
|
||||||
return this->player_.getCards();
|
return this->player_.getCards();
|
||||||
@@ -133,7 +143,6 @@ namespace UNO::GAME {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ClientGameState::draw(const Card &card)
|
void ClientGameState::draw(const Card &card)
|
||||||
{
|
{
|
||||||
this->player_.draw(card);
|
this->player_.draw(card);
|
||||||
|
|||||||
@@ -316,7 +316,17 @@ namespace UNO::GAME {
|
|||||||
void nextPlayer() override;
|
void nextPlayer() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ClientGameState(std::string name);
|
ClientGameState();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置玩家名字
|
||||||
|
*/
|
||||||
|
void setPlayerName(const std::string &name);
|
||||||
|
/**
|
||||||
|
* 获取当前玩家的名字
|
||||||
|
* @return 玩家名字
|
||||||
|
*/
|
||||||
|
[[nodiscard]] std::string getPlayerName() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当前手牌
|
* 获得当前手牌
|
||||||
|
|||||||
@@ -59,13 +59,19 @@ namespace UNO::GAME {
|
|||||||
this->cards_.clear();
|
this->cards_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::Player(std::string name) : name_(std::move(name)) {}
|
Player::Player() = default;
|
||||||
|
|
||||||
const std::string &Player::getName() const
|
const std::string &Player::getName() const
|
||||||
{
|
{
|
||||||
return this->name_;
|
return this->name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::setName(const std::string &name)
|
||||||
|
{
|
||||||
|
this->name_ = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::multiset<Card> &Player::getCards() const
|
const std::multiset<Card> &Player::getCards() const
|
||||||
{
|
{
|
||||||
return this->handCard_.getCards();
|
return this->handCard_.getCards();
|
||||||
|
|||||||
@@ -75,13 +75,15 @@ namespace UNO::GAME {
|
|||||||
HandCard handCard_;
|
HandCard handCard_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Player(std::string name);
|
Player();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 返回玩家名字
|
* @return 返回玩家名字
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] const std::string &getName() const;
|
[[nodiscard]] const std::string &getName() const;
|
||||||
|
|
||||||
|
void setName(const std::string &name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得当前手牌
|
* 获得当前手牌
|
||||||
* @return 当前手牌的集合
|
* @return 当前手牌的集合
|
||||||
|
|||||||
Reference in New Issue
Block a user