-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardEight.cpp
More file actions
103 lines (85 loc) · 1.61 KB
/
CardEight.cpp
File metadata and controls
103 lines (85 loc) · 1.61 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
#include"CardEight.h"
CardEight::CardEight(const CellPosition& pos) :Card(pos)
{
cardNumber = 8;
Amount = 0;
}
CardEight::~CardEight()
{
}
void CardEight::ReadCardParameters(Grid* pGrid)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("New CardEight: Enter its amount ...");
int Coins;
bool Test = false;
do
{
Coins = pIn->GetInteger(pOut);
if (!(Coins > 0))
{
pOut->PrintMessage("Invalid number try again...");
}
else
{
Test = true;
Amount = Coins;
}
} while (!Test);
pOut->ClearStatusBar();
}
void CardEight::Apply(Grid* pGrid, Player* pPlayer)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
Card::Apply(pGrid, pPlayer);
if (pPlayer->GetWallet() < Amount)
{
pOut->PrintMessage("Not enough coins! Go to prison");
pPlayer->SetTurnsDisabled(3);
return;
}
pOut->PrintMessage("Now choose whether paying " + to_string(Amount) + "coins (type 1) or going to prison(type 2)...");
int Choice;
bool Test = false;
Choice = pIn->GetInteger(pOut);
pOut->ClearStatusBar();
do
{
switch (Choice)
{
case 1:
{
pPlayer->SetWallet(pPlayer->GetWallet() - Amount);
Test = true;
}
break;
case 2:
{
pPlayer->SetTurnsDisabled(3);
Test = true;
}
break;
default:
{
pOut->PrintMessage("Invalid number try again...");
Choice = pIn->GetInteger(pOut);
}
break;
}
} while (!Test);
}
void CardEight::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
OutFile << Amount << endl;
}
}
void CardEight::Load(ifstream& Infile)
{
Card::Load(Infile);
Infile >> Amount;
}