-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinion.cc
More file actions
executable file
·154 lines (132 loc) · 4.11 KB
/
Minion.cc
File metadata and controls
executable file
·154 lines (132 loc) · 4.11 KB
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
#include <iostream>
#include <string>
#include <sstream>
#include "Minion.h"
#include "Player.h"
#include "Ability.h"
#include "Enchantment.h"
#define dbg false
using namespace std;
Minion::Minion(const string &name,int attack, int defence, int cost, Ability *actAbl, Ability *trgAbl): Card{name, cost},
attack{attack}, defence{defence}, activatedAbility{actAbl}, triggeredAbility{trgAbl} {
action = 1;
}
Minion::~Minion() {
delete dynamic_cast<ActivatedAbility*>(activatedAbility);
activatedAbility = nullptr;
delete dynamic_cast<TriggeredAbility*>(triggeredAbility);
triggeredAbility = nullptr;
for(auto &c : enchantments)
delete c;
// ?? Do we also need to delete the vector??
}
void Minion::updateActivatedAbility(Card *Ench){
// updates the activated ability by adding Enchantment to the vector of enchantments
enchantments.push_back(Ench);
}
void Minion::resetDefault(){
// Removes the enchantments if any on the Minion
while(!enchantments.empty()){
enchantments.pop_back();
}
}
void Minion::attackOther(Minion *minion){
// reduces the this->defence by the minion->attack, and minion->defence by this->attack
if(this->action){
minion->defence -= this->attack;
}
this->action = 0;
}
void Minion::attackOther(Player *player){
// reduces the this->defence by the minion->attack, and minion->defence by this->attack
if(this->action > 0){
// reduce the player's life by one
player->changeLife(-1);
} else {
cout << "You don't have enought action to attack" << endl;
}
this->action = 0;
}
void Minion::performAbility(){
// performs ability
}
void Minion::performActivatedAbility(int minionNum, Minion *minion, Player *p1, Player *p2) {
if (enchantments.empty()) {
ActivatedAbility *ab = dynamic_cast<ActivatedAbility*>(activatedAbility);
if(dbg) cout << "Performing Activated Ability with act Cost " << ab->getActCost() << " and player Magic " << p1->getMagic() << endl;
if(p1->getMagic() >= ab->getActCost()) {
ab->performAbility(" ", minionNum, minion, p1, p2);
p1->changeMagic(ab->getActCost() * -1);
} else {
cout << "You don't have enough magic to use this ability" << endl;
}
} else {
Enchantment *top = dynamic_cast<Enchantment*>(enchantments.back());
top->performActivatedAbility(minionNum, minion, p1, p2);
}
}
void Minion::performTriggeredAbility(string what, int minionNum, Minion *minion, Player *p1, Player *p2) {
//auto tAbility = dynamic_cast<TriggeredAbility*>(triggeredAbility);
if(dbg) cout << "Enter Minion For perfromTriggeredAbility" << endl;
if(triggeredAbility) {
if (dbg) cout << "triggeredAbility is not nullptr" << endl;
dynamic_cast<TriggeredAbility*>(triggeredAbility)->performTAbility(what, minionNum, this, minion, p1, p2);
}
}
bool Minion::isDead() {
// returns true if the minion is dead
return (this->defence <= 0);
}
void Minion::addToBoard(Card *ritualSlot, Card *MinionCardForEnch, Slot *slot){
// calls absractDeck's add card functionality
//slot->add(this);
}
void Minion::changeAttack(int val) {
this->attack += val;
};
void Minion::changeDefence(int val) {
this->defence += val;
};
void Minion::popTopEnchantment() {
if(enchantments.size() > 0) {
enchantments.pop_back();
}
}
void Minion::reInitializeDefence(int initialisationVal) {
defence = initialisationVal;
}
void Minion::setActionTo1() {
action = 1;
}
bool Minion::hasAbility() {
return !(triggeredAbility == nullptr && activatedAbility == nullptr);
}
bool Minion::hasTriggeredAbility(){
return !(triggeredAbility == nullptr);
}
int Minion::getAttack() {
return attack;
}
int Minion::getCost(){
return getCardCost();
}
int Minion::getDefence() {
return defence;
}
int Minion::getAction() {
return action;
}
Ability* Minion::getAbility() {
if (activatedAbility == nullptr) {
return triggeredAbility;
}
return activatedAbility;
}
int Minion::getActAbilityCost() {
if(activatedAbility)
return dynamic_cast<ActivatedAbility*>(activatedAbility)->getActCost();
return -1;
}
void Minion::setActAbilityCost(int setVal) {
dynamic_cast<ActivatedAbility*>(activatedAbility)->changeActCost(setVal);
}