-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.cc
204 lines (188 loc) · 4.62 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <iostream>
#include "cell.h"
#include "Enemy.h"
#include "gold.h"
#include "potion.h"
#include <memory>
Cell::Cell(): x(-1), y(-1), symbol(' '), isPlayerValid(false), isEnemyValid(false), dragonHoard(false), obj(nullptr) {}
Cell::Cell(int x, int y, char sym, GameObject& player): x(x), y(y), symbol(sym), origSym(sym), isPlayerValid(false), isEnemyValid(false), dragonHoard(false), obj(nullptr) {
if(sym == '.') {
isEnemyValid = true;
isPlayerValid = true;
}
else if(sym == '#' || sym == '+' || sym == 'G') {
isPlayerValid = true;
isEnemyValid = false;
}
else if(sym == 'H') {
symbol = 'H';
origSym = '.';
GameObject* human = new Human(x,y);
obj = human;
}
else if(sym == 'W') {
symbol = 'W';
origSym = '.';
GameObject* dwarf = new Dwarf(x,y);
obj = dwarf;
}
else if(sym == 'E') {
symbol = 'E';
origSym = '.';
GameObject* elf = new Elf(x,y);
obj = elf;
}
else if(sym == 'O') {
symbol = 'O';
origSym = '.';
GameObject* orc = new Orc(x,y);
obj = orc;
}
else if(sym == 'M') {
symbol = 'M';
origSym = '.';
GameObject* merchant = new Merchant(x,y);
obj = merchant;
}
/* else if(sym == 'D') {
symbol = 'D';
origSym = '.';
GameObject* dragon = new Dragon(x,y);
obj = dragon;
}*/
else if(sym == 'L') {
symbol = 'L';
origSym = '.';
GameObject* halfling = new Halfling(x,y);
obj = halfling;
}
else if(sym == '0') {
symbol = 'P';
origSym = '.';
GameObject* restoreHp = new RestoreHp(x,y);
obj = restoreHp;
}
else if(sym == '1') {
symbol = 'P';
origSym = '.';
GameObject* boostAtk = new BoostAtk(x,y);
obj = boostAtk;
}
else if(sym == '2') {
symbol = 'P';
origSym = '.';
GameObject* boostDef = new BoostDef(x,y);
obj = boostDef;
}
else if(sym == '3') {
symbol = 'P';
origSym = '.';
GameObject* poisonHp = new PoisonHp(x,y);
obj = poisonHp;
}
else if(sym == '4') {
symbol = 'P';
origSym = '.';
GameObject* woundAtk = new WoundAtk(x,y);
obj = woundAtk;
}
else if(sym == '5') {
symbol = 'P';
origSym = '.';
GameObject* woundDef = new WoundDef(x,y);
obj = woundDef;
}
else if(sym == '6') {
symbol = 'G';
origSym = '.';
GameObject* regGold = new Gold(x,y,2);
obj = regGold;
}
else if(sym == '7') {
symbol = 'G';
origSym = '.';
GameObject* smGold = new Gold(x,y,1);
obj = smGold;
}
else if(sym == '8') {
symbol = 'G';
origSym = '.';
GameObject* merGold = new Gold(x,y,4);
obj = merGold;
}
else if(sym == '9') {
symbol = 'G';
origSym = '.';
GameObject* dragGold = new Gold(x,y,6);
obj = dragGold;
}
else if(sym == '@') {
origSym = '.';
obj = &player;
player.setx(x);
player.sety(y);
}
else if(sym == '\\') {
symbol = '\\';
origSym = '\\';
}
else {}
}
int Cell::getx() { return x; }
int Cell:: gety() { return y; }
char Cell::getOrigSym() { return origSym; }
char Cell::getSymbol() {
return symbol;
}
bool Cell::getDragonHoard(){
return dragonHoard;
}
void Cell::setDragonHoard(bool status){
dragonHoard = status;
}
GameObject* Cell::getObject() {
return obj;
}
void Cell::add(GameObject* object) {
obj = object;
symbol = obj->getSymbol();
if(symbol == 'G') isPlayerValid = true;
else isPlayerValid = false;
isEnemyValid = false;
}
void Cell::remove() {
if(dragonHoard == true){
std::cout << "calling dragonhoard" << std::endl;
//GameObject *p = new Gold(getx(), gety(), 6);
//obj=p;
//symbol = obj->getSymbol();
//isEnemyValid = false;
}
else {
if(symbol == 'P' || symbol == 'G') {
delete obj;
}
else if(obj && obj->getHP() >= 0) obj = nullptr;
symbol = getOrigSym();
isEnemyValid = true;
if(symbol == '+' || symbol == '#') {
isEnemyValid = false;
}
}
isPlayerValid = true;
}
void Cell::setSymbol(char sym) {
symbol = sym;
}
bool Cell::getPlayerValid() {
return isPlayerValid;
}
bool Cell::getEnemyValid() {
return isEnemyValid;
}
void Cell::setPlayerValid(bool value) {
isPlayerValid = value;
}
void Cell::setEnemyValid(bool value) {
isEnemyValid = value;
}