-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCards.h
72 lines (60 loc) · 2.07 KB
/
Cards.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef CARDS_H
#define CARDS_H
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <experimental/memory>
#include "Effects.h"
class Player;
class Board;
class Card
{
protected:
// Id
int m_id;
// The card's owner
std::experimental::observer_ptr<Player> m_owner;
// The card can be linked to a board
std::experimental::observer_ptr<Board> m_board;
const unsigned int m_gold_cost = 3;
unsigned int m_gold_sell = 1;
// The card's effects
std::vector<std::unique_ptr<Effect>> m_effects;
virtual void printType() const = 0;
public:
Card(unsigned int gold_cost, std::vector<std::unique_ptr<Effect>> effects = {}) : m_gold_cost(gold_cost), m_effects(std::move(effects))
{
static int id = 0;
m_id = id++;
}
virtual ~Card() {}
unsigned int getGoldCost() const { return m_gold_cost; }
unsigned int getGoldSell() const { return m_gold_sell; }
void setGoldSell(unsigned int gold_sell) { m_gold_sell = gold_sell; }
int getId() const { return m_id; }
// Link the card to a board
void linkBoard(std::experimental::observer_ptr<Board> board) { m_board = board; }
void linkPlayer(std::experimental::observer_ptr<Player> player) { m_owner = player; }
void print() const;
// Apply the effects of the card
void applyEffects(Effect::ActivationPhase_e phase) const
{
for (const auto &effect : m_effects)
{
if (effect->getActivationPhase() == phase)
effect->activate();
}
}
// get Effects of the card
std::vector<std::unique_ptr<Effect>> &getEffects() { return m_effects; }
// add Effect to the card
void addEffect(std::unique_ptr<Effect> effect) { m_effects.push_back(std::move(effect)); }
std::experimental::observer_ptr<Player> getOwner() const { return m_owner; }
virtual int getRang() const = 0;
// Get the board
std::experimental::observer_ptr<Board> getBoard() { return m_board; }
virtual void printName() const = 0;
virtual const std::string getName() const = 0;
};
#endif