mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
- Added `clear` methods to `PlayerState`, `ServerPlayerState`, and `HandCard`. - Introduced `endGame` methods to `GameState`, `ClientGameState`, and `ServerGameState`. - Improved `init` and `nextPlayer` logic in `ClientGameState`. - Added `getClientGameStage` and `getServerGameStage` methods to retrieve game stages.
122 lines
2.3 KiB
C++
122 lines
2.3 KiB
C++
/**
|
|
* @file Player.h
|
|
*
|
|
* 玩家
|
|
*
|
|
* @author Yuzhe Guo
|
|
* @date 2025.11.15
|
|
*/
|
|
#ifndef UNO_GAME_PLAYER_H
|
|
#define UNO_GAME_PLAYER_H
|
|
#include <set>
|
|
#include <vector>
|
|
|
|
#include "Card.h"
|
|
|
|
namespace UNO::GAME {
|
|
/**
|
|
* 玩家手牌
|
|
*/
|
|
class HandCard {
|
|
private:
|
|
std::multiset<Card> cards_;
|
|
|
|
private:
|
|
/**
|
|
* 打出一张牌
|
|
* @param it 要打出的手牌的迭代器
|
|
*/
|
|
void play(const std::multiset<Card>::iterator &it);
|
|
|
|
public:
|
|
explicit HandCard();
|
|
|
|
/**
|
|
* 获得当前手牌
|
|
* @return 当前手牌的集合
|
|
*/
|
|
[[nodiscard]] const std::multiset<Card> &getCards() const;
|
|
|
|
/**
|
|
* 摸一张牌
|
|
* @param card 摸的牌
|
|
*/
|
|
void draw(const Card &card);
|
|
|
|
/**
|
|
* 摸多张牌
|
|
* @param cards 摸的牌
|
|
*/
|
|
void draw(const std::vector<Card> &cards);
|
|
|
|
/**
|
|
* 打出一张牌
|
|
* @param card 要打出的手牌
|
|
*/
|
|
void play(const Card &card);
|
|
|
|
/**
|
|
* @return 手牌是否为空
|
|
*/
|
|
[[nodiscard]] bool isEmpty() const;
|
|
|
|
/**
|
|
* 清空手牌
|
|
*/
|
|
void clear();
|
|
};
|
|
|
|
/**
|
|
* 玩家
|
|
*/
|
|
class Player {
|
|
private:
|
|
std::string name_;
|
|
HandCard handCard_;
|
|
|
|
public:
|
|
explicit Player(std::string name);
|
|
|
|
/**
|
|
* @return 返回玩家名字
|
|
*/
|
|
[[nodiscard]] const std::string &getName() const;
|
|
|
|
/**
|
|
* 获得当前手牌
|
|
* @return 当前手牌的集合
|
|
*/
|
|
[[nodiscard]] const std::multiset<Card> &getCards() const;
|
|
|
|
/**
|
|
* 摸一张牌
|
|
* @param card 摸的牌
|
|
*/
|
|
void draw(const Card &card);
|
|
|
|
/**
|
|
* 摸多张牌
|
|
* @param cards 摸的牌
|
|
*/
|
|
void draw(const std::vector<Card> &cards);
|
|
|
|
/**
|
|
* 打出一张牌
|
|
* @param card 要打出的手牌
|
|
*/
|
|
void play(const Card &card);
|
|
|
|
/**
|
|
* @return 手牌是否为空
|
|
*/
|
|
[[nodiscard]] bool isEmpty() const;
|
|
|
|
/**
|
|
* 清空手牌
|
|
*/
|
|
void clear();
|
|
};
|
|
} // namespace UNO::GAME
|
|
|
|
#endif // UNO_GAME_PLAYER_H
|