mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
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:
@@ -167,6 +167,13 @@ namespace UNO::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()
|
||||
{
|
||||
while (discardPile_.isEmpty() || discardPile_.getFront().getType() > CardType::NUM9) {
|
||||
|
||||
@@ -175,12 +175,6 @@ namespace UNO::GAME {
|
||||
|
||||
[[nodiscard]] size_t getDrawCount() const;
|
||||
|
||||
/**
|
||||
* 向对局中添加玩家
|
||||
* @param playerState 要添加的玩家状态
|
||||
*/
|
||||
void addPlayer(PlayerStateType playerState);
|
||||
|
||||
/**
|
||||
* 清空玩家
|
||||
*/
|
||||
@@ -235,15 +229,6 @@ namespace UNO::GAME {
|
||||
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>
|
||||
void GameState<PlayerStateType>::nextPlayer()
|
||||
{
|
||||
@@ -398,6 +383,12 @@ namespace UNO::GAME {
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* 向对局中添加玩家
|
||||
* @param playerState 要添加的玩家状态
|
||||
*/
|
||||
void addPlayer(ServerPlayerState playerState);
|
||||
|
||||
/**
|
||||
* 由于用户摸牌而改变状态
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user