-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialAttack.cpp
80 lines (64 loc) · 2.67 KB
/
SpecialAttack.cpp
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
#include "SpecialAttack.h"
SpecialAttack::SpecialAttack(Grid* Gr) {
check = true;
pGrid = Gr;
} // Constructor
// ============ Virtual Functions ============
void SpecialAttack::ReadParameters() {
Player* pPlayer = pGrid->GetCurrentPlayer();
if (pPlayer->getSpecialUses()>0) {
pGrid->GetOutput()->PrintMessage("Choose a special attack type (ice=0,fire=1,poison=2,lightning=3): ");
int attack = pGrid->GetInput()->GetInteger(pGrid->GetOutput());
if (attack != ICE && attack != FIRE && attack != POISON && attack != LIGHTNING) {
pGrid->PrintErrorMessage("Error: invalid input. Click to continue..");
check = false;
return;
}
if (pPlayer->getSpecialAttack() == (SpecialAttackType)attack) {
pGrid->PrintErrorMessage("You already chose this attack before. Click to continue...");
check = false;
return;
}
pPlayer->setSpecialAttack((SpecialAttackType)attack);
}
else
check = false;
} // Reads parameters required for action to execute
// (code depends on action type so virtual)
bool SpecialAttack::Execute() {
Player* pPlayer = pGrid->GetCurrentPlayer();
ReadParameters();
if (check == true) {
if (pPlayer->getSpecialAttack() == ICE) {
pGrid->GetOutput()->PrintMessage("ICE ATTACK: Choose player number to prevent from next turn:");
int playertoprevent = pGrid->GetInput()->GetInteger(pGrid->GetOutput());
pGrid->SkipTurnofPlayer(playertoprevent);
pPlayer->setSpecialUses(pPlayer->getSpecialUses() - 1);
}
else if (pPlayer->getSpecialAttack() == FIRE) {
pGrid->GetOutput()->PrintMessage("FIRE ATTACK: Choose player number to burn:");
int playertoburn= pGrid->GetInput()->GetInteger(pGrid->GetOutput());
Player* ap=pGrid->GetPlayerwithNumber(playertoburn);
ap->setFirecount(3);
pPlayer->setSpecialUses(pPlayer->getSpecialUses() - 1);
}
else if (pPlayer->getSpecialAttack() == POISON) {
pGrid->GetOutput()->PrintMessage("POISON ATTACK: Choose player number to poison:");
int playertopoison = pGrid->GetInput()->GetInteger(pGrid->GetOutput());
Player* ap = pGrid->GetPlayerwithNumber(playertopoison);
ap->SetPoisoned(5);
pPlayer->setSpecialUses(pPlayer->getSpecialUses() - 1);
}
else if (pPlayer->getSpecialAttack() == LIGHTNING) {
pGrid->PrintErrorMessage("DEDUCTING 20 COINS FROM ALL OTHER PLAYERS. Click to continue...");
pGrid->LightningOtherPlayers(pPlayer);
pPlayer->setSpecialUses(pPlayer->getSpecialUses() - 1);
}
pGrid->GetOutput()->ClearStatusBar();
return true;
}
else
return false;
} // Executes action (code depends on action type so virtual)
SpecialAttack::~SpecialAttack() {
} // Virtual Destructor