Represents a player's hand in the game.
More...
#include <hand.h>
|
| hand () |
| Constructs a new hand object.
|
|
| hand (const std::string &id, const std::vector< card * > &cards) |
| Constructs a new hand object during deserialization.
|
|
| hand (const std::string &id) |
| Constructs a new hand object (from_diff).
|
|
| ~hand () override |
| Destructs a hand object.
|
|
unsigned int | get_nof_cards () const |
| Gets the number of cards in the hand.
|
|
std::vector< card * > | get_cards () const |
| Gets the cards in the hand.
|
|
bool | try_get_card (const std::string &card_id, card *&hand_card) const |
| Tries to get a specific card from the hand.
|
|
bool | add_card (card *card, std::string &err) |
| Adds a card to the hand.
|
|
bool | remove_card (std::string card_id, std::string &err) |
| Removes a card from the hand.
|
|
void | write_into_json (rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override |
| Serializes a hand object into a json object.
|
|
std::string | get_id () const |
|
virtual void | write_into_json (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override |
|
virtual rapidjson::Document * | to_json () const |
|
|
static hand * | from_json (const rapidjson::Value &json) |
| Deserializes a hand object from a json object.
|
|
|
| unique_serializable (std::string id) |
|
std::string | _id |
|
Represents a player's hand in the game.
This class encapsulates all information about a player's hand, including the cards a player holds.
◆ hand() [1/2]
hand::hand |
( |
const std::string & | id, |
|
|
const std::vector< card * > & | cards ) |
Constructs a new hand object during deserialization.
- Parameters
-
id | The hand's id. |
cards | The hand's cards. |
◆ hand() [2/2]
hand::hand |
( |
const std::string & | id | ) |
|
|
explicit |
Constructs a new hand object (from_diff).
- Parameters
-
◆ add_card()
bool hand::add_card |
( |
card * | card, |
|
|
std::string & | err ) |
Adds a card to the hand.
- Parameters
-
card | The card to be added. |
err | The error message updated in case something does not work. |
- Returns
- A boolean indicating whether adding the card worked or not.
◆ from_json()
hand * hand::from_json |
( |
const rapidjson::Value & | json | ) |
|
|
static |
Deserializes a hand object from a json object.
- Parameters
-
json | The json object containing the hand information. |
- Returns
- A pointer to a new hand object created from the given json object.
◆ get_cards()
std::vector< card * > hand::get_cards |
( |
| ) |
const |
|
nodiscard |
Gets the cards in the hand.
- Returns
- The cards in the hand.
◆ get_nof_cards()
unsigned int hand::get_nof_cards |
( |
| ) |
const |
|
nodiscard |
Gets the number of cards in the hand.
- Returns
- The number of cards.
◆ remove_card()
bool hand::remove_card |
( |
std::string | card_id, |
|
|
std::string & | err ) |
Removes a card from the hand.
- Parameters
-
card_id | The id of the card that should be removed. |
err | The error message updated in case something does not work. |
- Returns
- A boolean indicating whether removing the card worked or not.
◆ try_get_card()
bool hand::try_get_card |
( |
const std::string & | card_id, |
|
|
card *& | hand_card ) const |
Tries to get a specific card from the hand.
- Parameters
-
card_id | The card's id. |
hand_card | Pointer that will point to the card if found. |
- Returns
- A boolean indicating whether getting the card worked or not.
This function tries to find a card in the hand given a provided card id. If the card is found, the given pointer reference will be updated to point to that card and true is returned, otherwise false is returned.
◆ write_into_json()
void hand::write_into_json |
( |
rapidjson::Value & | json, |
|
|
rapidjson::Document::AllocatorType & | allocator ) const |
|
overridevirtual |
Serializes a hand object into a json object.
- Parameters
-
json | The json object for serializing the hand. |
allocator | The json allocator for serializing the hand. |
Implements serializable.
The documentation for this class was generated from the following files:
- src/common/game_state/player/hand.h
- src/common/game_state/player/hand.cpp