Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
trick.h
1//
2// Created by Aidan Meara on 2024.11.08.
3//
4
5#ifndef WIZARD_TRICK_H
6#define WIZARD_TRICK_H
7
8#include <vector>
9#include "card.h"
10#include "../player/player.h"
11#include "../../serialization/unique_serializable.h"
12#include "../../serialization/serializable_value.h"
13#include "../../../../rapidjson/include/rapidjson/document.h"
14
28class trick : public unique_serializable {
29private:
30
31 serializable_value<int>* _trick_color;
32 serializable_value<int>* _trump_color;
33 std::vector<std::pair<card*, player*>> _cards;
34
35public:
36// constructor and destructors
40 trick();
41
46 explicit trick(const std::string& id);
47
55 trick(const std::string& id,
56 const std::vector<std::pair<card*, player*>> &cards,
57 serializable_value<int>* trick_color,
58 serializable_value<int>* trump_color);
59
64 explicit trick(int trump);
65
69 ~trick() override;
70
71// accessors
76 [[nodiscard]] int get_trick_color() const;
77
82 [[nodiscard]] std::vector<std::pair<card*, player*>> get_cards_and_players() const;
83
88 [[nodiscard]] int get_trump_color() const;
89
90#ifdef WIZARD_SERVER
91// state update functions
100 void set_up_round(int trump, std::string& err);
101
113 player* wrap_up_trick(std::string& err) const;
114
126 bool add_card(card* played_card, player* current_player, std::string& err);
127
128// server setter
133 void set_trick_color(int color) const;
134#endif
135
136// serializable interface
142 void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
143
149 static trick* from_json(const rapidjson::Value& json);
150
151};
152
153#endif //WIZARD_TRICK_H
Represents a card in the game.
Definition card.h:15
Represents a player in the game.
Definition player.h:18
Definition serializable_value.h:27
Represents the trick in the game.
Definition trick.h:28
void set_trick_color(int color) const
Sets the trick color.
Definition trick.cpp:142
static trick * from_json(const rapidjson::Value &json)
Deserializes a trick object from a json object.
Definition trick.cpp:149
std::vector< std::pair< card *, player * > > get_cards_and_players() const
Gets the played cards and players who played them as pairs.
Definition trick.cpp:56
~trick() override
Destructs a trick object.
Definition trick.cpp:37
bool add_card(card *played_card, player *current_player, std::string &err)
Adds a card to the trick.
Definition trick.cpp:124
player * wrap_up_trick(std::string &err) const
Wraps up a trick at the end of a trick or round.
Definition trick.cpp:72
trick()
Constructs a new trick object.
Definition trick.cpp:10
int get_trick_color() const
Gets the trick color.
Definition trick.cpp:46
int get_trump_color() const
Gets the trump color.
Definition trick.cpp:51
void write_into_json(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator) const override
Serializes a trick object into a json object.
Definition trick.cpp:175
void set_up_round(int trump, std::string &err)
Sets up a trick.
Definition trick.cpp:64
Definition unique_serializable.h:12