-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit.cpp
More file actions
199 lines (178 loc) · 2.85 KB
/
Copy pathunit.cpp
File metadata and controls
199 lines (178 loc) · 2.85 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
#include <string>
#include <cassert>
#include "unit.h"
using namespace std;
// Constructor
Unit::Unit(UnitType t, bool sd, int row, int col)
: type(t), side(sd), ifDisarm(false), urow(row), ucol(col)
{
switch (type)
{
case SOLDIER:
hp = 2, atk = 1;
break;
case TANK:
hp = 3, atk = 1;
break;
case BEE:
hp = 3, atk = 2;
break;
case FLIGHTER_JET:
hp = 2, atk = 2;
break;
case HYDRALISK:
hp = 1, atk = 1;
break;
default:
hp = 0;
atk = 0;
}
actable = {true, true}; // move and attack
}
// Get the symbol of the unit
string Unit::getSymbol() const
{
switch (type)
{
case SOLDIER:
if (side)
return "S";
else
return "s";
break;
case TANK:
if (side)
return "T";
else
return "t";
break;
case BEE:
if (side)
return "B";
else
return "b";
break;
case FLIGHTER_JET:
if (side)
return "F";
else
return "f";
break;
case HYDRALISK:
if (side)
return "H";
else
return "h";
break;
default:
return "";
}
}
// Get the coordinate of the current unit
int Unit::getRow() const
{
return urow;
}
int Unit::getCol() const
{
return ucol;
}
UnitType Unit::getType() const
{
return type;
}
int Unit::getHP() const
{
return hp;
}
int Unit::getAtk() const
{
return atk;
}
Position Unit::getPosition() const
{
switch (type)
{
case SOLDIER:
case TANK:
case HYDRALISK:
return LAND;
case BEE:
case FLIGHTER_JET:
return AIR;
default:
return LAND;
}
}
// Set the coordinates
void Unit::setCoord(int row, int col)
{
urow = row;
ucol = col;
}
// unit performs move action
void Unit::move(int row, int col)
{
setCoord(row, col);
}
void Unit::got_attacked(int atk)
{
hp -= atk;
}
bool Unit::getSide() const
{
return side;
}
// Get movement point
int Unit::getMovPoints() const
{
switch (type)
{
case SOLDIER:
return 3;
case TANK:
return 2;
case BEE:
return 4;
case FLIGHTER_JET:
return 5;
case HYDRALISK:
return 3;
default:
return 0;
}
}
bool Unit::getActable()
{
return actable[0] || actable[1];
}
bool Unit::getMoveActable() const
{
return actable[0];
}
bool Unit::getAttackActable() const
{
return actable[1];
}
void Unit::resetActable()
{
if (ifDisarm)
{
actable = {true, false};
ifDisarm = false;
}
else
actable = {true, true};
}
void Unit::moveActed()
{
actable[0] = false;
}
void Unit::attackActed()
{
actable[1] = false;
}
void Unit::disarmed()
{
ifDisarm = true;
}