-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseMonster.cc
166 lines (135 loc) · 4.44 KB
/
baseMonster.cc
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
#include <string>
#include "baseMonster.h"
#include "owner.h"
#include "ascii_graphics.h"
using namespace std;
BaseMonster::BaseMonster(string name, int cost, string description, int att, int def, TriggerType t,Effect *e, int effectCost): Monster(name, cost, description), attack{att}, defense{def}, Trigger{t}, effect{e}, effectCost{effectCost}, hasAttacked{false}{}
BaseMonster::~BaseMonster() {
delete effect;
}
//Copy Constructor
BaseMonster::BaseMonster(const BaseMonster &other) : Monster(other), attack{other.attack}, defense{other.defense}, Trigger{other.Trigger}, effectCost{other.effectCost}, hasAttacked{other.hasAttacked}{
if (other.effect) {
Effect* temp = other.effect->copyCtor();
effect = temp;
} else {
effect = nullptr;
}
}
//Move Constructor
BaseMonster::BaseMonster(BaseMonster &&other) : Monster(other), attack{other.attack}, defense{other.defense}, Trigger{other.Trigger}, effect{other.effect}, effectCost{other.effectCost}, hasAttacked{other.hasAttacked}{
other.effect = nullptr;
}
//Copy Assignment Operator
BaseMonster &BaseMonster::operator=(const BaseMonster &other) {
if(this == &other) return *this;
BaseMonster temp = other; //calls deep copy constructor
swap(attack, temp.attack);
swap(defense, temp.defense);
swap(Trigger, temp.Trigger);
swap(effect, temp.effect);
swap(effectCost, temp.effectCost);
swap(hasAttacked, temp.hasAttacked);
return *this;
}
//Move Assignment Operator
BaseMonster &BaseMonster::operator=(BaseMonster &&other) {
swap(attack, other.attack);
swap(defense, other.defense);
swap(Trigger, other.Trigger);
swap(effect, other.effect);
swap(effectCost, other.effectCost);
swap(hasAttacked, other.hasAttacked);
return *this;
}
string BaseMonster::getCompName() const {
return Card::getName();
}
int BaseMonster::getCompCost() const {
return Card::getCost();
}
string BaseMonster::getCompDescription() const {
return Card::getDescription();
}
void BaseMonster::notify(Owner* me, Owner* opponent, string &event) {
if(this->effect) this->effect->activate(me, opponent);
}
void BaseMonster::notify(Owner* me, Owner* opponent, int fieldIndex, int whoSummon) {
if(this->effect){
if (whoSummon == 1) {
this->effect->activate(fieldIndex, me);
} else {
this->effect->activate(fieldIndex, opponent);
}
}
}
void BaseMonster::disenchant() {
throw string("NoEnchantment");
}
void BaseMonster::play(Owner* me, Owner* opponent) {
BaseMonster* temp = new BaseMonster(*this);
me->summon(temp);
}
void BaseMonster::play(int fieldIndex, Owner* player){
throw string("NoNeedIndex");
}
void BaseMonster::changeHasAttacked(bool hasAttacked){
this->hasAttacked = hasAttacked;
}
bool BaseMonster::getHasAttacked() const{
return this->hasAttacked;
}
int BaseMonster::getAttack() const{
return this->attack;
}
int BaseMonster::getDefense() const{
return this->defense;
}
TriggerType BaseMonster::getTriggerType() const{
return this->Trigger;
}
void BaseMonster::changeStats(int attChange, int defChange) {
attack += attChange;
defense += defChange;
}
void BaseMonster::activate(Owner* me, Owner* opponent) {
if(this->effect){
this->effect->activate(me, opponent);
}else{
throw string("NoEffect");
}
}
void BaseMonster::activate(int fieldIndex, Owner* player) {
if(this->effect){
this->effect->activate(fieldIndex, player);
}else{
throw string("NoEffect");
}
}
int BaseMonster::getEffectCost() const{
return this->effectCost;
}
Monster* BaseMonster::getComponent() {
throw string("NoEnchantments");
}
Effect* BaseMonster::getEffect() const{
return this->effect;
}
card_template_t BaseMonster::makeTemplate() const{
if(effect == nullptr){
return display_minion_no_ability(Card::getName(), Card::getCost(), this->attack, this->defense);
}else if(Trigger == TriggerType::None){
return display_minion_activated_ability(Card::getName(), Card::getCost(), this->attack, this->defense, this->effectCost, Card::getDescription());
}else{
return display_minion_triggered_ability(Card::getName(), Card::getCost(), this->attack, this->defense, Card::getDescription());
}
}
card_template_t BaseMonster::getMonsterTemplate() const{
return makeTemplate();
}
vector<vector<card_template_t>> BaseMonster::makeCompleteTemplate() const {
card_template_t monsterTemplate = this->makeTemplate();
vector<card_template_t> line1 { monsterTemplate };
vector<vector<card_template_t>> completeTemplate { line1 };
return completeTemplate;
}