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