-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
322 lines (252 loc) · 6.22 KB
/
Copy pathPlayer.cpp
File metadata and controls
322 lines (252 loc) · 6.22 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include "Player.h"
#include "GameObject.h"
Player::Player(Cell * pCell, int playerNum) : stepCount(0), health(10), playerNum(playerNum), currDirection(RIGHT) , hasDoubleLaser(false), hasToolkit (false), hasHackDevice (false)
{
this->pCell = pCell;
//constructor edited by heba
// Make all the needed initialization or validations
///By Eyad : init move and shoot default to true.
canMove = true;
canShoot = true;
beingShot = false;
hasShield = false;
hasRefGear = false;
}
// ====== Setters and Getters ======
void Player::SetCell(Cell * cell)
{
pCell = cell;
}
Cell* Player::GetCell() const
{
return pCell;
}
int Player::GetPlayerNum() const
{
return playerNum;
}
void Player::SetHealth(int h)
{
//if by Eyad:
if (h >=0 && h<=10)
{
this->health = h;
}
///TODO: Do any needed validations
}
int Player::GetHealth()
{
return this->health;
}
///////By Eyad : shoot and move setters and getters.
void Player::SetCanMove(bool value) { canMove = value; }
bool Player::CanMove() const { return canMove; }
void Player::SetCanShoot(bool value) { canShoot = value; }
bool Player::CanShoot() const { return canShoot; }
void Player::ResetTurn(){ canShoot = true, canMove = true, beingShot= false; }
////////////////////////Consumables functions///////////By_Eyad///////////////////
void Player::SetHasToolkit(bool x)
{
hasToolkit = x;
}
bool Player::GetHasToolkit()
{
return hasToolkit;
}
// ====== Drawing Functions ======
void Player::Draw(Output* pOut) const
{
color playerColor = UI.PlayerColors[playerNum];
pOut->DrawPlayer(pCell->GetCellPosition(),playerNum,playerColor,currDirection);
///TODO: use the appropriate output function to draw the player with "playerColor"
}
void Player::ClearDrawing(Output* pOut) const
{
color cellColor = UI.CellColor; // Default color, assuming no game object
// Use the Output function to draw the player at this position with the background color
pOut->DrawPlayer(pCell->GetCellPosition(), playerNum, cellColor, currDirection);
}
// ====== Game Functions ======
void Player::Move(Grid* pGrid, Command moveCommands[])
{
int x = 0;
int y = 0;
Player* current = pGrid->GetCurrentPlayer();
Cell* known = current->GetCell();
CellPosition place = known->GetCellPosition();
for (int i = 0; i < sizeof(moveCommands) + 1;i++) {
switch (moveCommands[i]) {
case NO_COMMAND:
break;
case MOVE_FORWARD_ONE_STEP:
place.AddCellNum(1, current->currDirection);
break;
case MOVE_BACKWARD_ONE_STEP:
reverse();
place.AddCellNum(1, current->currDirection);
reverse();
break;
case MOVE_FORWARD_TWO_STEPS:
place.AddCellNum(2, current->currDirection);
break;
case MOVE_BACKWARD_TWO_STEPS:
reverse();
place.AddCellNum(2, current->currDirection);
reverse();
break;
case MOVE_FORWARD_THREE_STEPS:
place.AddCellNum(3, current->currDirection);
break;
case MOVE_BACKWARD_THREE_STEPS:
reverse();
place.AddCellNum(3, current->currDirection);
reverse();
break;
case ROTATE_CLOCKWISE:
ClearDrawing(pGrid->GetOutput());
currDirection = (Direction)((currDirection + 3) % 4);
break;
case ROTATE_COUNTERCLOCKWISE:
ClearDrawing(pGrid->GetOutput());
currDirection = (Direction)((currDirection + 1) % 4);
break;
default:
break;
}
pGrid->UpdatePlayerCell(current, place);
pGrid->GetOutput()->PrintMessage("click anywhere to excute next command");
pGrid->GetInput()->GetPointClicked(x, y);
}
///TODO: Implement this function using the guidelines mentioned below
if (current->GetCell()->GetGameObject() != nullptr){
current->GetCell()->GetGameObject()->Apply(pGrid, current);
}
if (pGrid->GetEndGame()) {
pGrid->GetOutput()->PrintMessage("Game finished ,click anywhere ");
pGrid->GetInput()->GetPointClicked(x, y);
return;
}
}
void Player::AppendPlayerInfo(string & playersInfo) const
{
// TODO: Modify the Info as needed
playersInfo += "P" + to_string(playerNum) + "(" ;
playersInfo += to_string(currDirection) + ", ";
playersInfo += to_string(health) + ")";
playersInfo += "Equipment: ";
if (hasDoubleLaser == true)
playersInfo += "Double Laser, ";
if (hasToolkit == true)
playersInfo += "Toolkit, ";
if (hasHackDevice == true)
playersInfo += "Hack Device, ";
if (!hasDoubleLaser && !hasToolkit && !hasHackDevice)
playersInfo += "None";
}
void Player::RotateRight()
{
switch (playerDirection)
{
case UP: playerDirection = RIGHT;
break;
case RIGHT: playerDirection = DOWN;
break;
case DOWN: playerDirection = LEFT;
break;
case LEFT: playerDirection = UP;
break;
}
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Player rotated 90° clockwise!");
}
void Player::RotateLeft()
{
switch (playerDirection)
{
case UP: playerDirection = LEFT;
break;
case LEFT: playerDirection = DOWN;
break;
case DOWN: playerDirection = RIGHT;
break;
case RIGHT: playerDirection = UP;
break;
}
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Player rotated 90° counterclockwise!");
}
void Player::EquipDoubleLaser()
{
hasDoubleLaser = true;
}
void Player::AddToolkit()
{
hasToolkit = true;
}
void Player::AddHackDevice()
{
hasHackDevice = true;
}
bool Player::HasDoubleLaser() const
{
return hasDoubleLaser;
}
bool Player::HasToolkit() const
{
return hasToolkit;
}
bool Player::HasHackDevice() const
{
return hasHackDevice;
}
bool skipTurn = false;
void Player::SkipNextTurn()
{
skipTurn = true;
}
bool Player::IsTurnSkipped() const
{
return skipTurn;
}
Direction Player::getDirection(){return currDirection;}
void Player::takeDamage()
{
beingShot= true;
///////////////////////////check shield;;;
//////////better check it when calling the func;
////
if (health>0)
{
health -=2;
}
}
void Player::setHasShield(bool x){ hasShield = x; }
bool Player::getHasShield(){ return hasShield;}
//
void Player::setRefGear(bool x){ hasRefGear = x;}
bool Player::getRefGear(){return hasRefGear;}
void Player::reverse() {
switch (currDirection) {
case RIGHT:
currDirection = LEFT;
break;
case LEFT:
currDirection = RIGHT;
break;
case UP:
currDirection = DOWN;
break;
case DOWN:
currDirection = UP;
break;
}
}
void Player::ResetAll()
{
canMove = true;
canShoot = true;
beingShot = false;
hasShield = false;
hasRefGear = false;
////reset cell;
}