-
Notifications
You must be signed in to change notification settings - Fork 1
/
card11.cpp
182 lines (170 loc) · 3.54 KB
/
card11.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
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
#include "card11.h"
#include<fstream>
card11::card11(const CellPosition & pos) : Card(pos) // set the cell position of the card
{
cardNumber = 11;// set the inherited cardNumber data member with the card number (11 here)
taken =5;
mor=5;
offer=false;
made = 0;
}
card11::~card11(void)
{
}
void card11::ReadCardParameters(Grid * pGrid)
{
do{
pGrid->PrintErrorMessage("Hurghada City selected: Enter its Price in POSITIVE integer,click ");
price= pGrid->GetInput()->GetInteger(pGrid->GetOutput());
}while(price<0);
do{
pGrid->PrintErrorMessage("Enter the POSITIVE fees of Hurghada City ,click ");
fees= pGrid->GetInput()->GetInteger(pGrid->GetOutput());
}while(fees<0);
}
void card11::reset()
{
taken =5;
mor=5;
offer=false;
}
int card11::getmor()
{
return mor;
}
void card11::setmor(int x)
{
mor=x;
}
int card11::getfee()
{
return fees;
}
int card11::getprice()
{
return price;
}
void card11::settaken(int x)
{
taken=x;
}
int card11::gettaken()
{
return taken;
}
void card11::setprice(int x)
{
price=x;
}
void card11::setfees(int x)
{
fees=x;
}
void card11::setoffer(bool x)
{
offer=x;
}
bool card11::getoffer()
{
return offer;
}
void card11::Apply(Grid* pGrid, Player* pPlayer)
{ if(pGrid->isbenefit()!=NULL)
{
Player* benefit=pGrid->isbenefit();
if(benefit->getpnum()!=pPlayer->getpnum())
{
pPlayer->SetWallet(pPlayer->GetWallet()-fees);
pGrid->getplayer(benefit->getpnum())->SetWallet(pGrid->getplayer(benefit->getpnum())->GetWallet()+fees);
}
}
else
{
if(taken==5 && pPlayer->GetWallet()>=price)
{
pGrid->GetOutput()->PrintMessage("Monopoly Card Hurghada City reached! Do you want to buy it?? click then y/n");
string choice = pGrid->GetInput()->GetSrting(pGrid->GetOutput());
if(choice=="y")
{
pPlayer->SetWallet(pPlayer->GetWallet()-price);
pGrid->setmonopoly(this->GetCardNumber(),pPlayer->getpnum());
}
else
return ;
}
else if(taken!=5 && mor==5)
{
if(pPlayer->getpnum()!=taken)
{
pPlayer->SetWallet(pPlayer->GetWallet()-fees);
pGrid->getplayer(taken)->SetWallet(pGrid->getplayer(taken)->GetWallet()+fees);
}
}
else if(taken!=5 && mor!=5&& mor!=taken)
{
if(pPlayer->getpnum()!=mor)
{
pPlayer->SetWallet(pPlayer->GetWallet()-fees);
pGrid->getplayer(mor)->SetWallet(pGrid->getplayer(mor)->GetWallet()+fees);
}
}
else if(taken!=5 && mor!=5&& mor==taken)
{
mor=5;
if(pPlayer->getpnum()!=taken)
{
pPlayer->SetWallet(pPlayer->GetWallet()-fees);
pGrid->getplayer(taken)->SetWallet(pGrid->getplayer(taken)->GetWallet()+fees);
}
}
}
pGrid->UpdateInterface();
pGrid->GetOutput()->ClearStatusBar();
}
void card11::setmade(bool m)
{
if (m == 0 || m == 1)
{
made = m;
}
else
{
return;
}
}
bool card11::getmade()
{
return made;
}
void card11::Save(ofstream& OutFile, Grid* pGrid, int typ)
{
Card::Save(OutFile, pGrid, typ);
Card* pCard = pGrid->CheckCardNumber(cardNumber);
if ((pCard->GetCardNumber() >= 7 && pCard->GetCardNumber() <= 11))
{
if (getmade() == 0)
{
OutFile << getprice() << " " << getfee() << endl;
pGrid->SetSave(GetCardNumber());
}
else
{
OutFile << endl;
return;
}
}
}
void card11::Load(ifstream& InFile, Grid* pGrid, int typ)
{
if (pGrid->getcity(11) == NULL)
{
InFile >> price >> fees;
setprice(price);
setfees(fees);
}
else
{
setprice(pGrid->getcity(11)->getprice());
setfees(pGrid->getcity(11)->getfee());
}
}