-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.cc
132 lines (111 loc) · 3.95 KB
/
cell.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
#include "cell.h"
#include "potion.h"
#include "dragon.h"
#include "goblin.h"
#include "troll.h"
#include "werewolf.h"
#include "vampire.h"
#include "phoenix.h"
#include "merchant.h"
#include "enemy.h"
#include <iostream>
Cell::Cell(size_t r, size_t c, State s) : r{ r }, c{ c }, s{ s } {}
// My neighbours will call this
// when they've changed state
void Cell::notify(Subject& whoFrom) {
}
State Cell::getState() const {
return this->s;
}
void Cell::setState(const State& newState) {
this->s = newState;
}
Info Cell::getInfo() {
Info i{r,c,s};
return i;
}
Cell& Cell::operator=(const Cell& c) {
if(&c == this) { return *this; }
this->r = c.r;
this->c = c.c;
this->s = c.s;
Cell tmp{ c };
std::swap(this->enemy, tmp.enemy);
std::swap(this->potion, tmp.potion);
return *this;
}
AbstractPotion* Cell::getPotion() noexcept {
return potion;
}
Enemy* Cell::getEnemy() {
return enemy;
}
void Cell::setPotion(AbstractPotion* p) {
delete potion;
potion = p;
}
void Cell::setEnemy(Enemy* e) {
delete enemy;
enemy = e;
}
Cell::Cell(const Cell& c) {
this->r = c.r;
this->c = c.c;
this->s = c.s;
if (c.potion != nullptr) {
if (c.potion->getName() == "RH") {
this->potion = new RH{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "RH" };
}
else if (c.potion->getName() == "BA") {
this->potion = new BA{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "BA" };
}
else if (c.potion->getName() == "BD") {
this->potion = new BD{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "BD" };
}
else if (c.potion->getName() == "PH") {
this->potion = new PH{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "PH" };
}
else if (c.potion->getName() == "WA") {
this->potion = new WA{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "WA" };
}
else {
this->potion = new WD{ c.potion->getHP(), c.potion->getAtk(), c.potion->getDef(), "WD" };
}
}
if (c.enemy != nullptr) {
if (c.enemy->getName() == "vampire") {
this->enemy = new Vampire{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"vampire",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "werewolf") {
this->enemy = new Werewolf{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"werewolf",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "goblin") {
this->enemy = new Goblin{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"goblin",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "merchant") {
this->enemy = new Merchant{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"merchant",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "dragon") {
this->enemy = new Dragon{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"dragon",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "phoenix") {
this->enemy = new Phoenix{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"phoenix",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
else if (c.enemy->getName() == "troll") {
this->enemy = new Troll{ c.enemy->getHP(), c.enemy->getAtk(), c.enemy->getDef(),"troll",
c.enemy->getGold(), c.enemy->getMove(), c.enemy->getCompass() };
}
}
}
Cell::~Cell() {
delete enemy;
enemy = nullptr;
delete potion;
potion = nullptr;
}