Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
hand.h
1#ifndef WIZARD_HAND_H
2#define WIZARD_HAND_H
3
4#include <vector>
5#include "../../../../rapidjson/include/rapidjson/document.h"
6#include "../cards/card.h"
7
15class hand : public unique_serializable {
16private:
17
18 std::vector<card*> _cards;
19
25 card* remove_card(std::vector<card*>::iterator pos);
26
32 card* remove_card(int idx);
33
39 card* remove_card(card* card);
40
41public:
42
43// constructors and destructor
47 hand();
48
54 hand(const std::string& id, const std::vector<card*>& cards);
55
60 explicit hand(const std::string& id);
61
65 ~hand() override;
66
67// accessors
72 [[nodiscard]] unsigned int get_nof_cards() const;
73
78 [[nodiscard]] std::vector<card*> get_cards() const;
79
89 bool try_get_card(const std::string& card_id, card*& hand_card) const;
90
91#ifdef WIZARD_SERVER
92// state update functions
99 bool add_card(card* card, std::string& err);
100
107 bool remove_card(std::string card_id, std::string& err);
108#endif
109
110// serialization interface
116 void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
117
123 static hand* from_json(const rapidjson::Value& json);
124
125};
126
127#endif //WIZARD_HAND_H
Represents a card in the game.
Definition card.h:15
Represents a player's hand in the game.
Definition hand.h:15
bool try_get_card(const std::string &card_id, card *&hand_card) const
Tries to get a specific card from the hand.
Definition hand.cpp:33
void write_into_json(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Serializes a hand object into a json object.
Definition hand.cpp:83
static hand * from_json(const rapidjson::Value &json)
Deserializes a hand object from a json object.
Definition hand.cpp:88
std::vector< card * > get_cards() const
Gets the cards in the hand.
Definition hand.cpp:27
bool add_card(card *card, std::string &err)
Adds a card to the hand.
Definition hand.cpp:64
unsigned int get_nof_cards() const
Gets the number of cards in the hand.
Definition hand.cpp:23
hand()
Constructs a new hand object.
Definition hand.cpp:7
~hand() override
Destructs a hand object.
Definition hand.cpp:18
Definition unique_serializable.h:12