refactor(server): move addPlayer implementation to ServerGameState

- Relocated `addPlayer` method from template-based `GameState` to `ServerGameState`.
- Updated method signature and comments for better clarity.
This commit is contained in:
Kieran Kihn
2025-12-07 19:32:40 +08:00
parent a1c46b8c9b
commit d266f1c514
2 changed files with 13 additions and 15 deletions

View File

@@ -167,6 +167,13 @@ namespace UNO::GAME {
ServerGameState::ServerGameState() : serverGameStage_(ServerGameStage::PRE_GAME) {} ServerGameState::ServerGameState() : serverGameStage_(ServerGameStage::PRE_GAME) {}
void ServerGameState::addPlayer(ServerPlayerState playerState)
{
long long currentPlayerIndex = this->currentPlayer_ - this->players_.begin();
this->players_.push_back(std::move(playerState));
this->currentPlayer_ = this->players_.begin() + currentPlayerIndex;
}
void ServerGameState::init() void ServerGameState::init()
{ {
while (discardPile_.isEmpty() || discardPile_.getFront().getType() > CardType::NUM9) { while (discardPile_.isEmpty() || discardPile_.getFront().getType() > CardType::NUM9) {

View File

@@ -175,12 +175,6 @@ namespace UNO::GAME {
[[nodiscard]] size_t getDrawCount() const; [[nodiscard]] size_t getDrawCount() const;
/**
* 向对局中添加玩家
* @param playerState 要添加的玩家状态
*/
void addPlayer(PlayerStateType playerState);
/** /**
* 清空玩家 * 清空玩家
*/ */
@@ -235,15 +229,6 @@ namespace UNO::GAME {
return this->drawCount_; return this->drawCount_;
} }
template<PlayerStateTypeConcept PlayerStateType>
void GameState<PlayerStateType>::addPlayer(PlayerStateType playerState)
{
int currentPlayerIndex = this->currentPlayer_ - this->players_.begin();
this->players_.push_back(std::move(playerState));
this->currentPlayer_ = this->players_.begin() + currentPlayerIndex;
}
template<PlayerStateTypeConcept PlayerStateType> template<PlayerStateTypeConcept PlayerStateType>
void GameState<PlayerStateType>::nextPlayer() void GameState<PlayerStateType>::nextPlayer()
{ {
@@ -398,6 +383,12 @@ namespace UNO::GAME {
*/ */
void init(); void init();
/**
* 向对局中添加玩家
* @param playerState 要添加的玩家状态
*/
void addPlayer(ServerPlayerState playerState);
/** /**
* 由于用户摸牌而改变状态 * 由于用户摸牌而改变状态
*/ */