forked from hwauck/statue-puzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemyUnit.cc
executable file
·140 lines (114 loc) · 2.65 KB
/
EnemyUnit.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
#include "EnemyUnit.h"
#include "type.h"
#include "Square.h"
#include "ccc_win.h"
#include "drawConstants.h"
EnemyUnit::EnemyUnit() {
this->name = "Unit";
this->speed = 50;
this->type = Type();
this->goldReward = 100;
this->scoreReward = 1;
this->maxHealth = 200;
this->health = 200;
this->color = "black";
this->distanceTraveled = 0;
this->square = Square();
}
EnemyUnit::EnemyUnit(std::string name, int speed, Type type, int goldReward, int scoreReward, int maxHealth, std::string color, Square square) {
this->name = name;
this->speed = speed;
this->type = type;
this->goldReward = goldReward;
this->scoreReward = scoreReward;
this->maxHealth = maxHealth;
this->health = maxHealth;
this->color = color;
this->square = square;
this->distanceTraveled = 0;
}
void EnemyUnit::move(Square square) {
setSquare(square);
distanceTraveled++;
drawUnit();
}
void EnemyUnit::takeDamage(Tower tower) {
Type towerType = tower.getType();
int totalDamage = tower.getDamage();
if (type.getWeakness() == towerType.getName()) {
totalDamage *= type.getMultiplier();
} else if (type.getStrength() == towerType.getName()) {
totalDamage /= type.getMultiplier();
}
health -= totalDamage;
tower.attack(square);
drawUnit();
}
bool EnemyUnit::isDead() {
if (health <= 0) {
return true;
}
return false;
}
void EnemyUnit::drawUnit() {
Point position = square.get_location();
Point adjustedPosition = Point (position.get_x() + 0.4, position.get_y() + 0.4, color);
cwin << adjustedPosition;
}
void EnemyUnit::setName(std::string name) {
this->name = name;
}
void EnemyUnit::setSpeed(int speed) {
this->speed = speed;
}
void EnemyUnit::setType(Type type) {
this->type = type;
}
void EnemyUnit::setGoldReward(int goldReward) {
this->goldReward = goldReward;
}
void EnemyUnit::setScoreReward(int scoreReward) {
this->scoreReward = scoreReward;
}
void EnemyUnit::setDirection(char direction) {
this->direction = direction;
}
void EnemyUnit::setMaxHealth(int maxHealth) {
this->maxHealth = maxHealth;
}
void EnemyUnit::setColor(std::string color) {
this->color = color;
}
void EnemyUnit::setSquare(Square square) {
this->square = square;
}
std::string EnemyUnit::getName() {
return name;
}
int EnemyUnit::getSpeed() {
return speed;
}
Type EnemyUnit::getType() {
return type;
}
int EnemyUnit::getGoldReward() {
return goldReward;
}
int EnemyUnit::getScoreReward() {
return scoreReward;
}
int EnemyUnit::getMaxHealth() {
return maxHealth;
}
char EnemyUnit::getDirection() {
return direction;
}
std::string EnemyUnit::getColor() {
return color;
}
Square EnemyUnit::getSquare() {
return square;
}
int EnemyUnit::getDistanceTraveled() {
return distanceTraveled;
}