-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlexandria.cpp
More file actions
148 lines (129 loc) · 3.25 KB
/
Alexandria.cpp
File metadata and controls
148 lines (129 loc) · 3.25 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
#include "Alexandria.h"
#include<string>
int Alexandria::CardPrice = 0;
int Alexandria::feesTopay = 0;
Player* Alexandria::owner = NULL;
bool Alexandria::isinitialize = false;
bool Alexandria::bought = false;
Player* Alexandria::Mortgagedto = NULL;
Player* Alexandria::BenefitTo = NULL;
int Alexandria::BenefitTurns = -1;
int Alexandria::count = 0;
Alexandria::Alexandria(const CellPosition& pos) :Card(pos)
{
cardNumber = 8;
Upformortgage = NULL;
}
void Alexandria::setparameters()
{
isinitialize = false;
}
void Alexandria::ReadCardParameters(Grid* pGrid)
{
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
if (isinitialize == false)
{
pOut->PrintMessage("New Card Alexandria: Please enter the CardPrice");
CardPrice = pIn->GetInteger(pOut);
pOut->PrintMessage("Please enter the Fees");
feesTopay = pIn->GetInteger(pOut);
isinitialize = true;
}
while (CardPrice < 0 || feesTopay < 0)
{
pGrid->PrintErrorMessage("Invalid value. Enter postitve values ...");
pOut->PrintMessage("Please enter the CardPrice");
CardPrice = pIn->GetInteger(pOut);
pOut->PrintMessage("Please enter the Fees");
feesTopay = pIn->GetInteger(pOut);
}
pOut->ClearStatusBar();
}
void Alexandria::Apply(Grid* pGrid, Player* pPlayer)
{
Card::Apply(pGrid, pPlayer);
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
if (!bought)
{
pOut->PrintMessage("Do you want to buy this Cell?Y/N");
string s = pIn->GetString(pOut);
if ((s == "Y" || s == "y") && pPlayer->GetWallet() > CardPrice)
{
owner = pPlayer;
Mortgagedto = pPlayer;
BenefitTo = pPlayer;
pPlayer->SetWallet(pPlayer->GetWallet() - CardPrice);
bought = true;
}
else if ((s == "Y" || "y") && pPlayer->GetWallet() < CardPrice)
{
pOut->PrintMessage("Sorry You don't have enough money in your Wallet to buy the Cell");
}
pGrid->ApplyforsameAlex(this);
}
if (bought)
{
if (BenefitTo != owner)
{
pPlayer->SetWallet(pPlayer->GetWallet() - feesTopay);
BenefitTo->SetWallet(BenefitTo->GetWallet() + feesTopay);
count++;
}
else if (pPlayer == owner)
{
if (Mortgagedto != NULL)
{
pPlayer->SetWallet(pPlayer->GetWallet() - feesTopay);
Mortgagedto->SetWallet(Mortgagedto->GetWallet() + feesTopay);
}
}
else
{
if (Mortgagedto != NULL)
{
pPlayer->SetWallet(pPlayer->GetWallet() - feesTopay);
Mortgagedto->SetWallet(Mortgagedto->GetWallet() + feesTopay);
}
else
{
pPlayer->SetWallet(pPlayer->GetWallet() - feesTopay);
owner->SetWallet(owner->GetWallet() + feesTopay);
}
}
if (count == BenefitTurns)
{
BenefitTo = owner;
}
}
}
int Alexandria::GetPrice() {
return CardPrice;
}
Alexandria::~Alexandria(void)
{
}
void Alexandria::Setbought(bool x)
{
bought = x;
}
bool Alexandria::Getbought()
{
return bought;
}
void Alexandria::ApplyforAlex(Alexandria* org, Alexandria* copy)
{
copy->owner = org->owner;
copy->Setbought(org->Getbought());
copy->Upformortgage = org->Upformortgage;
copy->Mortgagedto = org->Mortgagedto;
}
void Alexandria::SetCardParameters(int price, int fees) {
this->CardPrice = price;
this->feesTopay = fees;
}
void Alexandria::SaveToFile(ofstream& output, int obj) {
Card::SaveToFile(output, obj);
output << " " << this->CardPrice << " " << this->feesTopay << std::endl;
}