Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
deck.h
1//
2// Created by Michel Tarnow on 15.11.24.
3//
4
5#ifndef DECK_H
6#define DECK_H
7
8#include "card.h"
9#include "../player/player.h"
10#include <vector>
11#include "../../serialization/unique_serializable.h"
12#include "../../serialization/serializable_value.h"
13#include "../../../../rapidjson/include/rapidjson/document.h"
14
28{
29private:
30
31 std::vector<card*> _all_cards;
32 std::vector<card*> _remaining_cards;
33
40 deck(const std::string& id, const std::vector<card*> &all_cards, const std::vector<card*> &remaining_cards);
41
46 explicit deck(const std::string& id);
47
48public:
49// constructors & destructor
58 deck();
59
64 explicit deck(const std::vector<card*>& cards);
65
72 ~deck() override;
73
74// accessors
81 [[nodiscard]] bool is_empty() const noexcept;
82
87 [[nodiscard]] unsigned int get_number_of_remaining_cards() const noexcept;
88
89#ifdef WIZARD_SERVER
90// state update functions
96 void setup_round();
97
110 bool draw_cards(const player* player, int round_number, std::string& err);
111
120 [[nodiscard]] card* draw_trump() const;
121#endif
122
123// serialization
124
130 void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
131
137 static deck* from_json(const rapidjson::Value& json);
138
139};
140
141#endif //DECK_H
Represents a card in the game.
Definition card.h:15
Represents the card deck in the game.
Definition deck.h:28
deck()
Constructs a new deck object.
Definition deck.cpp:26
~deck() override
Destructs a deck object.
Definition deck.cpp:56
bool is_empty() const noexcept
Checks if _remaining_cards is empty, i.e., if all cards are dealt.
Definition deck.cpp:67
void setup_round()
Sets up the deck for a new round.
Definition deck.cpp:80
void write_into_json(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Serializes a deck object into a json object.
Definition deck.cpp:143
static deck * from_json(const rapidjson::Value &json)
Deserializes a deck object from a json object.
Definition deck.cpp:152
card * draw_trump() const
Draws a random trump card from the remaining cards.
Definition deck.cpp:122
unsigned int get_number_of_remaining_cards() const noexcept
Gets the number of remaining cards, i.e., the number of cards not dealt yet.
Definition deck.cpp:72
bool draw_cards(const player *player, int round_number, std::string &err)
Draws a number of random cards based on the current round number and places them into a player's hand...
Definition deck.cpp:85
Represents a player in the game.
Definition player.h:18
Definition unique_serializable.h:12