-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
186 lines (146 loc) · 3.99 KB
/
Copy pathPlayer.cpp
File metadata and controls
186 lines (146 loc) · 3.99 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
#include "Player.h"
#include "GameObject.h"
Player::Player(Cell* pCell, int playerNum) : stepCount(0), health(10), playerNum(playerNum), currDirection(RIGHT)
{
this->pCell = pCell;
hasToolkit = false;
hasHackDevice = false;
// Make all the needed initialization or validations
}
// ====== Setters and Getters ======
void Player::SetCell(Cell* cell)
{
pCell = cell;
}
Cell* Player::GetCell() const
{
return pCell;
}
void Player::SetHealth(int h)
{
this->health = h;
///TODO: Do any needed validations
}
int Player::GetHealth()
{
return this->health;
}
// ====== 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
{
///TODO: Modify the cellColor to draw the correct cellColor (hint: if cell contains non-default cellColor)
color cellColor = UI.CellColor;
pOut->DrawPlayer(pCell->GetCellPosition(), playerNum, cellColor, currDirection);
///TODO: use the appropriate output function to draw the player with "cellColor" (to clear it)
}
Direction Player::GetCurrentDirection() {
return currDirection;
}
void Player::SetDirection(Direction direction)
{
currDirection = direction;
}
// ====== 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 + 1) % 4);
break;
case ROTATE_COUNTERCLOCKWISE:
ClearDrawing(pGrid->GetOutput());
currDirection = (Direction)((currDirection + 3) % 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 += "Player H" + to_string(health) + ")";
}
int Player::getplayernum() {
return playerNum;
}
void Player::SetReflectionGear(bool hasRef)
{
hasReflectionGear = hasRef;
}
bool Player::GetReflectionGear()
{
return hasReflectionGear;
}
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::getshot() {
health--;
};