Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
hand Class Reference

Represents a player's hand in the game. More...

#include <hand.h>

Inheritance diagram for hand:
unique_serializable serializable

Public Member Functions

 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.
 
- Public Member Functions inherited from unique_serializable
std::string get_id () const
 
virtual void write_into_json (rapidjson::Value &json, rapidjson::MemoryPoolAllocator< rapidjson::CrtAllocator > &allocator) const override
 
- Public Member Functions inherited from serializable
virtual rapidjson::Document * to_json () const
 

Static Public Member Functions

static handfrom_json (const rapidjson::Value &json)
 Deserializes a hand object from a json object.
 

Additional Inherited Members

- Protected Member Functions inherited from unique_serializable
 unique_serializable (std::string id)
 
- Protected Attributes inherited from unique_serializable
std::string _id
 

Detailed Description

Represents a player's hand in the game.

This class encapsulates all information about a player's hand, including the cards a player holds.

Constructor & Destructor Documentation

◆ hand() [1/2]

hand::hand ( const std::string & id,
const std::vector< card * > & cards )

Constructs a new hand object during deserialization.

Parameters
idThe hand's id.
cardsThe hand's cards.

◆ hand() [2/2]

hand::hand ( const std::string & id)
explicit

Constructs a new hand object (from_diff).

Parameters
idThe hand's id.

Member Function Documentation

◆ add_card()

bool hand::add_card ( card * card,
std::string & err )

Adds a card to the hand.

Parameters
cardThe card to be added.
errThe 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
jsonThe 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_idThe id of the card that should be removed.
errThe 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_idThe card's id.
hand_cardPointer 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
jsonThe json object for serializing the hand.
allocatorThe json allocator for serializing the hand.

Implements serializable.


The documentation for this class was generated from the following files: