-
Notifications
You must be signed in to change notification settings - Fork 1
/
card10.cpp
183 lines (169 loc) · 3.48 KB
/
card10.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
183
#include "card10.h"
#include<fstream>
card10::card10(const CellPosition & pos) : Card(pos) // set the cell position of the card
{
cardNumber = 10;// set the inherited cardNumber data member with the card number (10 here)
taken =5;
mor=5;
offer=false;
made = 0;
}
card10::~card10(void)
{
}
void card10::ReadCardParameters(Grid * pGrid)
{
do{
pGrid->PrintErrorMessage("Luxor 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 Luxor City ,click ");
fees= pGrid->GetInput()->GetInteger(pGrid->GetOutput());
}while(fees<0);
}
void card10::reset()
{
taken =5;
mor=5;
offer=false;
}
int card10::getmor()
{
return mor;
}
void card10::setmor(int x)
{
mor=x;
}
int card10::getfee()
{
return fees;
}
int card10::getprice()
{
return price;
}
void card10::settaken(int x)
{
taken=x;
}
int card10::gettaken()
{
return taken;
}
void card10::setprice(int x)
{
price=x;
}
void card10::setfees(int x)
{
fees=x;
}
void card10::setoffer(bool x)
{
offer=x;
}
bool card10::getoffer()
{
return offer;
}
void card10::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->PrintErrorMessage("Monopoly Card Luxor reached! Do you want to buy it?? click then enter 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();
}
void card10:: setmade(bool m)
{
if(m==0 || m==1 )
{
made=m;
}
else
{
return;
}
}
bool card10::getmade()
{
return made;
}
void card10::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 card10::Load(ifstream& InFile, Grid* pGrid, int typ)
{
if (pGrid->getcity(10) == NULL)
{
InFile >> price >> fees;
setprice(price);
setfees(fees);
}
else
{
setprice(pGrid->getcity(10)->getprice());
setfees(pGrid->getcity(10)->getfee());
}
}