-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerCardDeck.cpp
64 lines (56 loc) · 1.93 KB
/
PlayerCardDeck.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
#include "PlayerCardDeck.h"
#include "EpidemicCard.h"
PlayerCardDeck::PlayerCardDeck(const rapidjson::Document &doc, const Vector2D pos, const std::string &deckName) : Deck(doc, pos, deckName)
{
mEpidemicIndeces = std::vector<int>();
mNumEpidemics = doc["game"]["numEpidemics"].GetUint();
}
PlayerCardDeck::~PlayerCardDeck()
{
}
bool PlayerCardDeck::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;
unsigned int numEpidemicsCounted = 0;
for(unsigned int i = 0; i < mCards.size(); i++)
{
if(mEpidemicIndeces.size() > numEpidemicsCounted && (mInitialDeckSize - mCards.size() + i) == mEpidemicIndeces[numEpidemicsCounted])
{
std::cout << "Epidemic!" << std:: endl;
numEpidemicsCounted++;
}
std::cout << mCards[i]->debugDescription() << std::endl;
}
return true;
}
}
return false;
}
PlayerCard *PlayerCardDeck::dealTopCard()
{
if(mEpidemicIndeces.size() > 0 && mInitialDeckSize - (int)mCards.size() >= mEpidemicIndeces.front())
{
mEpidemicIndeces.erase(mEpidemicIndeces.begin());
return new EpidemicCard(Vector2D(0, 0), new Sprite(*Game::getInstance()->getGraphicsBufferManager().getGraphicsBuffer("city_card.png")));
}
else
{
return Deck::dealTopCard();
}
}
void PlayerCardDeck::completeInit()
{
// "Place" epidemic cards at intervals with an average of, but no less than, the number of player cards / number of epidemics
mInitialDeckSize = mCards.size();
int averageEpidemicInterval = mInitialDeckSize / mNumEpidemics;
for(unsigned int i = 0; i < mNumEpidemics; i++)
{
int currentEpidemicInterval = std::rand() % averageEpidemicInterval + (averageEpidemicInterval * i);
mEpidemicIndeces.push_back(currentEpidemicInterval);
}
}