-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardEleven.cpp
More file actions
149 lines (137 loc) · 2.94 KB
/
CardEleven.cpp
File metadata and controls
149 lines (137 loc) · 2.94 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
#include "CardEleven.h"
int CardEleven::CardPrice = 0;
int CardEleven::Fees = 0;
int CardEleven::NumberOfCards = 0;
Player* CardEleven::Owner = nullptr;
bool CardEleven::IsSaved = false;
bool CardEleven::IsRead = false;
CardEleven::CardEleven(const CellPosition& cellposition) :Card(cellposition)
{
NumberOfCards++;
cardNumber = 11;
}
void CardEleven::ReadCardParameters(Grid* pGrid)
{
if (Fees==0) {
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pGrid->PrintErrorMessage("Card Eleven : Station 3 , click to continue..");
pOut->PrintMessage("Enter its Price : ");
int t;
do
{
t = pIn->GetInteger(pOut);
if (t > 0)
{
CardPrice = t;
}
else pOut->PrintMessage("Invalid Price ! please try again.");
} while (t <= 0);
pOut->PrintMessage("Enter its Fees : ");
do
{
t = pIn->GetInteger(pOut);
if (t > 0)
{
Fees = t;
}
else pOut->PrintMessage("Invalid Fees value ! please try again.");
} while (t <= 0);
pOut->ClearStatusBar();
}
}
void CardEleven::Apply(Grid* pGrid, Player* pPlayer)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
if (!Owner)
{
Card::Apply(pGrid, pPlayer);
pGrid->PrintErrorMessage("This is station 3 , Price : " + to_string(CardPrice) + " Fees : " + to_string(Fees) + " click to continue...");
pOut->PrintMessage("Would you like to purchase ? Yes(y) or No(n)");
string t;
do
{
t = pIn->GetSrting(pOut);
if (t == "y")
{
if (pPlayer->GetWallet() >= CardPrice) {
pPlayer->SetWallet(pPlayer->GetWallet() - CardPrice);
Owner = pPlayer;
pOut->PrintMessage("Purchase complete .");
}
else
{
pGrid->PrintErrorMessage("Insufficient wallet, click to continue.. ");
}
}
else if (t != "n") {
pOut->PrintMessage("Invalid input ! please try again. ");
}
} while (t != "y" && t != "n");
}
else
{
if (Owner != pPlayer)
{
pOut->PrintMessage("Stepped on a card owned by p(" + to_string(Owner->getPlayerNum()) + ") pay : " + to_string(Fees));
if (Fees < pPlayer->GetWallet())
Owner->SetWallet(Owner->GetWallet() + Fees);
else
Owner->SetWallet(Owner->GetWallet() + pPlayer->GetWallet());
pPlayer->SetWallet(pPlayer->GetWallet() - Fees);
}
}
}
Player* CardEleven::GetOwner()
{
return Owner;
}
void CardEleven::SetOwner(Player* pNew)
{
Owner = pNew;
}
int CardEleven::GetCardPrice()
{
return CardPrice;
}
void CardEleven::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
if (!IsSaved)
{
OutFile << CardPrice << " " << Fees;
IsSaved = true;
}
OutFile << endl;
}
}
void CardEleven::Load(ifstream& Infile)
{
Card::Load(Infile);
if (!IsRead)
{
Infile >> CardPrice >> Fees;
IsRead = true;
}
}
void CardEleven::SetIsSavedF()
{
IsSaved = false;
}
void CardEleven::SetIsReadF()
{
IsRead = false;
}
CardEleven::~CardEleven()
{
NumberOfCards--;
if (NumberOfCards == 0)
{
Fees = 0;
CardPrice = 0;
Owner = nullptr;
}
}