Skip to content
Snippets Groups Projects
card.h 1.34 KiB
Newer Older
ameara's avatar
ameara committed
#ifndef WIZARD_CARD_H
#define WIZARD_CARD_H
marie3003's avatar
marie3003 committed

#include <tuple>
marie3003's avatar
marie3003 committed
#include "../../serialization/unique_serializable.h"
#include "../../serialization/serializable_value.h"
#include "../../../../rapidjson/include/rapidjson/document.h"
#include "trick.h"
#include "../player/hand.h"
marie3003's avatar
marie3003 committed

class card : public unique_serializable {
private:

    // TODO: make sure that _value can only take numbers from 1 to 15 in first position and from 0 to 4 in second
    // _value contains the card number as first int (number between 1 and 13, or wizard (14) / jester (15)),
    // and also the color as second int (encoded as 1: yellow, 2: red, 3: green, 4: blue, 0 if wizard or jester)
    serializable_value<std::tuple<int, int>>* _value;
marie3003's avatar
marie3003 committed

    // from_diff constructor
    card(std::string id);
    // deserialization constructor
    card(std::string id, serializable_value<std::tuple<int, int>>* val);
marie3003's avatar
marie3003 committed
public:
    card(std::tuple<int, int> val);
marie3003's avatar
marie3003 committed
    ~card();

    // accessors
    std::tuple<int, int> get_value() const noexcept;
marie3003's avatar
marie3003 committed

    // card functions
    bool can_be_played(const trick* const current_trick, const hand* const current_hand) const noexcept;
marie3003's avatar
marie3003 committed

    // serializable interface
marie3003's avatar
marie3003 committed
    void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
    static card* from_json(const rapidjson::Value& json);
};


ameara's avatar
ameara committed
#endif //WIZARD_CARD_H