-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.cpp
115 lines (101 loc) · 2.49 KB
/
Deck.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "Deck.h"
#include "ColorManager.h"
#include "game.h"
#include "EventSystem.h"
#include <random>
template<typename T>
Deck<T>::Deck(const rapidjson::Document &doc, const Vector2D pos, const std::string &deckName) : mPosition(pos), mDeckName(deckName)
{
mTextBox = createDeckNameText(doc);
}
template<typename T>
Deck<T>::~Deck()
{
mTextBox = NULL;
}
template<typename T>
void Deck<T>::addCard(T * card, bool toBack)
{
gpEventSystem->fireEvent(new UnitMoveEvent(card, mPosition, 1000));
if(mCards.size() > 0)
{
mCards[mCards.size() - 1]->setIsHidden(true);
}
card->setIsHidden(false);
if(toBack)
{
mCards.push_back(card);
}
else
{
mCards.insert(mCards.begin(), card);
}
}
template<typename T>
bool Deck<T>::checkDeckForClick(Vector2D clickPosition, const std::string & opener) const
{
// Hacky, but we'll just ask the top card in each stack for its position
if(mCards.size() > 0)
{
if(mCards[0]->contains(clickPosition))
{
std::cout << opener << std::endl;
for(auto &a : mCards)
{
std::cout << a->debugDescription() << std::endl;
}
return true;
}
}
return false;
}
template<typename T>
T * Deck<T>::dealTopCard()
{
if(mCards.size() > 0)
{
T* card = static_cast<T*>(*mCards.begin());
card->setIsHidden(false);
mCards.erase(mCards.begin());
if(mCards.size() > 0)
{
mCards[0]->setIsHidden(false);
}
return card;
}
else
{
return nullptr;
}
}
template<typename T>
void Deck<T>::shuffle()
{
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(mCards.begin(), mCards.end(), g);
}
template<typename T>
Vector2D Deck<T>::getPosition() const
{
return mPosition;
}
template<typename T>
UIBox* Deck<T>::createDeckNameText(const rapidjson::Document &doc)
{
ColorManager& colorManager = *ColorManager::getInstance();
int deckNameFontSize = doc["deck"]["nameFontSize"].GetInt();
int deckNamePadding = doc["deck"]["namePadding"].GetInt();
int cardSize = doc["deck"]["cardHeight"].GetInt();
UIBox *deckNameText = new UIBox(
Vector2D(mPosition.getX(), mPosition.getY() + deckNamePadding + cardSize),
deckNameFontSize,
colorManager.color(doc["ui"]["darkUIColor"].GetString()),
mDeckName
);
deckNameText->setOutline(Outline(colorManager.white, colorManager.white, deckNamePadding));
gpEventSystem->fireEvent(new UnitAddEvent(deckNameText));
return deckNameText;
}
template class Deck<PlayerCard>;
template class Deck<InfectionCard>;