-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunit.cpp
More file actions
280 lines (214 loc) · 4.44 KB
/
unit.cpp
File metadata and controls
280 lines (214 loc) · 4.44 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include <iostream>
#include <stdlib.h>
using namespace std;
#include "main.h"
#include "item.h"
#include "prop.h"
#include "unit.h"
#include "hero.h"
#include "pet.h"
#include "board.h"
//------------------------------------------------------------------------------
// class Unit
//------------------------------------------------------------------------------
Unit::Unit() {
init('U', -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
Unit::Unit(char shape, int row, int col, int dir, int hp, int maxHp, int mp, int maxMp, int atk, int def, int gold, int exp) {
init(shape, row, col, dir, hp, maxHp, mp, maxMp, atk, def, gold, exp);
}
void Unit::init(char shape, int row, int col, int dir, int hp, int maxHp, int mp, int maxMp, int atk, int def, int gold, int exp) {
this->shape = shape;
this->row = row;
this->col = col;
this->dir = dir;
this->hp = hp;
this->maxHp = maxHp;
this->mp = mp;
this->maxMp = maxMp;
this->atk = atk;
this->def = def;
this->gold = gold;
this->exp = exp;
board = NULL;
died = false;
frozen = false;
}
Unit::~Unit() {
}
void Unit::print() {
cout << shape;
}
void Unit::printStat() {
cout << "[" << shape << "]: HP(" << hp << "/" << maxHp << ") MP(" << mp << "/" << maxMp << ") ATK(" << atk << ") DEF(" << def << ") GOLD(" << gold << ") EXP(" << exp << ")";
}
void Unit::setBoard(Board *board) {
this->board = board;
}
int Unit::getRow() {
return row;
}
void Unit::setRow(int row) {
this->row = row;
}
int Unit::getCol() {
return col;
}
void Unit::setCol(int col) {
this->col = col;
}
int Unit::getDir() {
return dir;
}
char Unit::getShape() {
return shape;
}
bool Unit::incHp(int hpInc) {
if (hp == maxHp) {
return false;
}
if (hp + hpInc >= maxHp) {
hp = maxHp;
}
else {
hp += hpInc;
}
return true;
}
void Unit::decHp(int hpDec) {
if (hp - hpDec <= 0) {
hp = 0;
died = true;
}
else {
hp -= hpDec;
}
}
int Unit::getMp() {
return mp;
}
bool Unit::incMp(int mpInc) {
if (mp == maxMp) {
return false;
}
if (mp + mpInc >= maxMp) {
mp = maxMp;
}
else {
mp += mpInc;
}
return true;
}
void Unit::decMp(int mpDec) {
if (mp - mpDec <= 0) {
mp = 0;
}
else {
mp -= mpDec;
}
}
// 이 rpg에서는 오직 weapon과 armor로만 atk와 def를 더하고 빼므로, 0 아래로 떨어질 일은 없다. 또한 max는 inf이다.
int Unit::getAtk() {
return atk;
}
void Unit::incAtk(int atkInc) {
atk += atkInc;
}
void Unit::decAtk(int atkDec) {
atk -= atkDec;
}
int Unit::getDef() {
return def;
}
void Unit::incDef(int defInc) {
def += defInc;
}
void Unit::decDef(int defDec) {
def -= defDec;
}
int Unit::getGold() {
return gold;
}
void Unit::incGold(int gold) {
this->gold += gold;
}
bool Unit::decGold(int gold) {
if (this->gold < gold) {
return false;
}
this->gold -= gold;
return true;
}
int Unit::getExp() {
return exp;
}
void Unit::incExp(int exp) {
this->exp += exp;
}
void Unit::decExp(int exp) {
this->exp -= exp;
}
bool Unit::isDead() {
return died;
}
bool Unit::isFrozen() {
return frozen;
}
void Unit::freeze() {
frozen = true;
}
void Unit::unfreeze() {
frozen = false;
}
bool Unit::isHero() { // fake body
return false;
}
bool Unit::isMonster() { // fake body
return false;
}
bool Unit::isBoss() { // fake body
return false;
}
bool Unit::isPet() { // fake body
return false;
}
bool Unit::isMerchant() { // fake body
return false;
}
void Unit::useItem(int index) { // fake body
}
void Unit::effect(Unit *unit, Item *item, Prop *prop, int skillNumber) { // fake body
}
bool Unit::equip(Item *itemToEquip) { // fake body
return false;
}
void Unit::unequip(int bodyPartIDToUnequip) { // fake body
}
bool Unit::canReceiveItem() { // fake body
return false;
}
// pre-condition: canReceiveItem() == true
void Unit::receiveItem(Item *item) { // fake body
}
void Unit::printSlots() {
}
void Unit::printBackpack() {
}
Item *Unit::getSlotItemAt(int index) {
return NULL;
}
Item *Unit::removeSlotItemAt(int index) {
return NULL;
}
int Unit::capacitySlots() {
return 0;
}
Item *Unit::getBackpackItemAt(int index) {
return NULL;
}
Item *Unit::removeBackpackItemAt(int index) {
return NULL;
}
int Unit::sizeBackpack() {
return 0;
}