-
Notifications
You must be signed in to change notification settings - Fork 2
/
Shop.cpp
167 lines (153 loc) · 5.98 KB
/
Shop.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "Shop.h"
#include "MinionsCards.h"
#include "Player.h"
unsigned int Shop::calculateGold(unsigned int turns) const
{
// Cap it to 10 golds
return turns > 10 ? 10 : turns ++;
}
void Shop::createDeck()
{
// Beasts
m_deck.push_back(std::make_unique<AlleyCat>());
m_deck.push_back(std::make_unique<AlleyCat>());
m_deck.push_back(std::make_unique<AlleyCat>());
m_deck.push_back(std::make_unique<AlleyCat>());
m_deck.push_back(std::make_unique<Scavenging_Hyena>());
m_deck.push_back(std::make_unique<Scavenging_Hyena>());
m_deck.push_back(std::make_unique<Scavenging_Hyena>());
m_deck.push_back(std::make_unique<Scavenging_Hyena>());
m_deck.push_back(std::make_unique<Leapfrogger>());
m_deck.push_back(std::make_unique<Leapfrogger>());
m_deck.push_back(std::make_unique<Leapfrogger>());
m_deck.push_back(std::make_unique<Rabid_Saurolisk>());
m_deck.push_back(std::make_unique<Rabid_Saurolisk>());
m_deck.push_back(std::make_unique<Rabid_Saurolisk>());
m_deck.push_back(std::make_unique<HoundMaster>());
m_deck.push_back(std::make_unique<HoundMaster>());
m_deck.push_back(std::make_unique<HoundMaster>());
m_deck.push_back(std::make_unique<Monstrous_macow>());
m_deck.push_back(std::make_unique<Monstrous_macow>());
m_deck.push_back(std::make_unique<Monstrous_macow>());
m_deck.push_back(std::make_unique<Cave_Hydra>());
m_deck.push_back(std::make_unique<Cave_Hydra>());
m_deck.push_back(std::make_unique<Reanimating_Rattler>());
m_deck.push_back(std::make_unique<Reanimating_Rattler>());
// Pirates
m_deck.push_back(std::make_unique<DeckSwabbie>());
m_deck.push_back(std::make_unique<DeckSwabbie>());
m_deck.push_back(std::make_unique<DeckSwabbie>());
m_deck.push_back(std::make_unique<DeckSwabbie>());
m_deck.push_back(std::make_unique<Scallywag>());
m_deck.push_back(std::make_unique<Scallywag>());
m_deck.push_back(std::make_unique<Scallywag>());
m_deck.push_back(std::make_unique<Scallywag>());
m_deck.push_back(std::make_unique<Freedealing_Gambler>());
m_deck.push_back(std::make_unique<Freedealing_Gambler>());
m_deck.push_back(std::make_unique<Freedealing_Gambler>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Salty_Looter>());
m_deck.push_back(std::make_unique<Salty_Looter>());
m_deck.push_back(std::make_unique<Salty_Looter>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Southsea_Captain>());
m_deck.push_back(std::make_unique<Peggy_Brittlebone>());
m_deck.push_back(std::make_unique<Peggy_Brittlebone>());
m_deck.push_back(std::make_unique<Ripsnarl_Captain>());
m_deck.push_back(std::make_unique<Ripsnarl_Captain>());
// Dragons
m_deck.push_back(std::make_unique<DozyWhelp>());
m_deck.push_back(std::make_unique<DozyWhelp>());
m_deck.push_back(std::make_unique<DozyWhelp>());
m_deck.push_back(std::make_unique<DozyWhelp>());
m_deck.push_back(std::make_unique<Glyph_Guardian>());
m_deck.push_back(std::make_unique<Glyph_Guardian>());
m_deck.push_back(std::make_unique<Glyph_Guardian>());
m_deck.push_back(std::make_unique<Whelp_Smuggler>());
m_deck.push_back(std::make_unique<Whelp_Smuggler>());
m_deck.push_back(std::make_unique<Whelp_Smuggler>());
m_deck.push_back(std::make_unique<Amber_Guardian>());
m_deck.push_back(std::make_unique<Amber_Guardian>());
m_deck.push_back(std::make_unique<Amber_Guardian>());
m_deck.push_back(std::make_unique<Bronze_Warden>());
m_deck.push_back(std::make_unique<Bronze_Warden>());
m_deck.push_back(std::make_unique<Bronze_Warden>());
m_deck.push_back(std::make_unique<Atramedes>());
m_deck.push_back(std::make_unique<Atramedes>());
m_deck.push_back(std::make_unique<Drakonid_Enforcer>());
m_deck.push_back(std::make_unique<Drakonid_Enforcer>());
}
void Shop::shuffleDeck()
{
std::random_shuffle(m_deck.begin(), m_deck.end());
}
void Shop::giveChoice(Player &player)
{
shuffleDeck();
int count = 0;
for (int i = 0; i < m_deck.size(); i++)
{
if (m_deck[i]->getRang() <= player.getLevel())
{
player.addCardToChoices(*m_deck[i]);
if (++count == 3)
break;
}
}
}
void Shop::giveAnotherChoice(Player &player)
{
shuffleDeck();
if (player.getGolds() < 1)
return;
player.setGolds(player.getGolds() - 1);
player.resetChoices();
int count = 0;
for (int i = 0; i < m_deck.size(); i++)
{
if (m_deck[i]->getRang() <= player.getLevel())
{
player.addCardToChoices(*m_deck[i]);
if (++count == 3)
break;
}
}
}
void Shop::sellCard(std::unique_ptr<Card> &card, Player *player)
{
// Add a gold to the player
player->setGolds(player->getGolds() + card->getGoldSell());
// card->setOwner(nullptr);
// Add the card to the shop
m_deck.push_back(std::move(card));
}
void Shop::giveGold(Player &player, unsigned int turns) const
{
player.m_golds = calculateGold(turns);
}
void Shop::giveCardToPlayer(Player &player, Card &card)
{
// Get index of the card in the deck
if (player.getGolds() < 3){
std::cout << "You don't have enough golds to buy card" << std::endl;
return;
}
int index = 0;
for (auto &c : m_deck)
{
if (c->getId() == card.getId())
break;
index++;
}
// Get the card
std::unique_ptr<Card> cardToGive = std::move(m_deck[index]);
// Remove the card from the deck
m_deck.erase(m_deck.begin() + index);
// Remove the gold cost of the card from the player
player.setGolds(player.getGolds() - 3);
cardToGive->linkPlayer(std::experimental::make_observer(&player));
player.addCardToHand(cardToGive);
}