-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShootingPhase.cpp
More file actions
134 lines (99 loc) · 3.67 KB
/
Copy pathShootingPhase.cpp
File metadata and controls
134 lines (99 loc) · 3.67 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
#include "ShootingPhase.h"
ShootingPhase::ShootingPhase(Grid * pGrid)
{
this->pGrid = pGrid;
pOut = pGrid->GetOutput();
player0 = pGrid->GetPlayer(0);
player1 = pGrid->GetPlayer(1);
}
void ShootingPhase::execute(Player* currentPlayer)
{
/////almost forgot the return if he cant shoot:
if (!(currentPlayer->CanShoot()))
{
pGrid->PrintErrorMessage("This player cant shoot this round");
return;
}
Player * otherPlayer = pGrid->getOtherPlayer();
////////////////if both has ref gear, to avoid recursion:
if (currentPlayer->getRefGear()&& otherPlayer->getRefGear())
{
pGrid->PrintErrorMessage("Both have ref gears, both wont take damage");
currentPlayer->setRefGear(false);
otherPlayer->setRefGear(false);
return;
}
/////def cells for curr and other player:
CellPosition pCurrCell = currentPlayer->GetCell()->GetCellPosition();
CellPosition pOtherCell = otherPlayer->GetCell()->GetCellPosition();
////case if they are in the same cell
if (pCurrCell.getVCell() == pOtherCell.getVCell()&&pCurrCell.getHCell()==pOtherCell.getHCell())
{
pGrid->PrintErrorMessage("Common Ground, No shooting phase this round");
return;
}
///same row:
if (pCurrCell.getHCell()==pOtherCell.getHCell())
{
if (pCurrCell.getVCell()<pOtherCell.getVCell())
{
if (currentPlayer->getDirection() != DOWN)
{
pGrid->PrintErrorMessage("Player is not facing enemies, no shooting this round");
return;
}
}
else if (pCurrCell.getVCell()>pOtherCell.getVCell())
{
if (currentPlayer->getDirection() != UP)
{
pGrid->PrintErrorMessage("Player is not facing enemies, no shooting this round");
return;
}
}
otherPlayer->takeDamage();
pGrid->PrintErrorMessage("Player: " + std::to_string(currentPlayer->GetPlayerNum()) + "has shot player: " + std::to_string(otherPlayer->GetPlayerNum()));
return;
}
//////////////////
if (pCurrCell.getVCell()==pOtherCell.getVCell())
{
if (pCurrCell.getHCell()<pOtherCell.getHCell())
{
if (currentPlayer->getDirection() != RIGHT)
{
pGrid->PrintErrorMessage("Player is not facing enemies, no shooting this round");
return;
}
}
else if (pCurrCell.getHCell()>pOtherCell.getHCell())
{
if (currentPlayer->getDirection() != LEFT)
{
pGrid->PrintErrorMessage("Player is not facing enemies, no shooting this round");
return;
}
}
if (otherPlayer->getHasShield())
{
pGrid->PrintErrorMessage("The other player has a shield, no damage dealt ! ");
otherPlayer->setHasShield(false);
return;
}
if (otherPlayer->getRefGear())
{
if (!(currentPlayer->getHasShield()))
{
currentPlayer->takeDamage();
}
pGrid->PrintErrorMessage("Jokes on you he has a reflection gear hahahaahah");
otherPlayer->setRefGear(false);
return;
}
otherPlayer->takeDamage();
pGrid->PrintErrorMessage("Player: " + std::to_string(currentPlayer->GetPlayerNum()) + "has shot player: " + std::to_string(otherPlayer->GetPlayerNum()));
return;
}
else
pGrid->PrintErrorMessage("No shooting phase this round!!");
}