Skip to content
Snippets Groups Projects
card.h 1.36 KiB
Newer Older
ameara's avatar
ameara committed
#ifndef WIZARD_CARD_H
#define WIZARD_CARD_H
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 as the cards value,
    // or wizard (14) / jester (0)), 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::pair<int, int>>* _value;
marie3003's avatar
marie3003 committed

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

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

    // card functions
    bool can_be_played(const trick* current_trick, const hand* 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