-
Notifications
You must be signed in to change notification settings - Fork 0
/
Luxor_10.cpp
142 lines (107 loc) · 3.11 KB
/
Luxor_10.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
#include"Luxor_10.h"
Luxor_10::Luxor_10(const CellPosition &position)
:Card(position){
cardNumber = 10;
m_cityOwner = NULL;
m_originalOwner = NULL;
isFirst = true;
}
Luxor_10::Luxor_10(){
cardNumber = 10;
}
void Luxor_10::ReadCardParameters(Grid *pGrid){
Input *inPtr = pGrid->GetInput();
Output *outPtr = pGrid->GetOutput();
if(pGrid->GetFirstCard(cardNumber)){
isFirst = false;
Luxor_10* firstCard = dynamic_cast<Luxor_10*>(pGrid->GetFirstCard(cardNumber));
m_cityPrice = firstCard->m_cityPrice;
m_rent = firstCard->m_rent;
outPtr->ClearStatusBar();
return;
}
outPtr->PrintMessage("New Monopoly Card (10) | Luxor City | Enter its Price: ");
m_cityPrice = inPtr->GetInteger(outPtr);
outPtr->PrintMessage("Luxor City | Enter its Rent: ");
m_rent = inPtr->GetInteger(outPtr);
outPtr->ClearStatusBar();
}
void Luxor_10::Apply(Grid *pGrid, Player *pPlayer){
Card::Apply(pGrid, pPlayer);
Input *inPtr = pGrid->GetInput();
Output *outPtr = pGrid->GetOutput();
int x, y;
if(!m_cityOwner){
string option;
do{
outPtr->PrintMessage("Do you want to buy Luxor City? .. (y | n)");
option = inPtr->GetSrting(outPtr);
} while(option != "y" && option != "Y" && option != "n" && option != "N");
if(option == "n" || option == "N"){
outPtr->ClearStatusBar();
return;
}
if(pPlayer->GetWallet() < m_cityPrice){
outPtr->PrintMessage("Sorry, you don't have enough coins to buy this city! Click to continue ...");
inPtr->GetPointClicked(x,y);
outPtr->ClearStatusBar();
return;
}
pPlayer->SetWallet(pPlayer->GetWallet() - m_cityPrice);
outPtr->PrintMessage("Your new wallet amount: " + to_string(pPlayer->GetWallet()) + " Coins");
inPtr->GetPointClicked(x,y);
outPtr->ClearStatusBar();
m_cityOwner = pPlayer;
pGrid->SetCityOwner(m_cityOwner, cardNumber);
}
else if(pPlayer->getPlayerNum() != m_cityOwner->getPlayerNum()){
pPlayer->SetWallet(pPlayer->GetWallet() - m_rent);
outPtr->PrintMessage("Your new wallet amount: " + to_string(pPlayer->GetWallet()) + " Coins");
inPtr->GetPointClicked(x, y);
outPtr->ClearStatusBar();
m_cityOwner->SetWallet(m_cityOwner->GetWallet() + m_rent);
outPtr->PrintMessage("Cairo City Owner's new wallet amount: " + to_string(m_cityOwner->GetWallet()) + " Coins");
inPtr->GetPointClicked(x, y);
outPtr->ClearStatusBar();
}
}
void Luxor_10::setCityOwner(Player* pPlayer){
m_cityOwner = pPlayer;
}
Player* Luxor_10::GetCityOwner() const{
return m_cityOwner;
}
void Luxor_10::SetOriginalOwner(Player* pPlayer){
m_originalOwner = pPlayer;
}
Player* Luxor_10::GetOriginalOwner() const{
return m_originalOwner;
}
int Luxor_10::GetCityPrice() const{
return m_cityPrice;
}
int Luxor_10::GetCityRent() const{
return m_rent;
}
Luxor_10::~Luxor_10(){}
void Luxor_10::Save(ofstream& outFile, Type gameObj)
{
if (gameObj == CARDS)
{
Card::Save(outFile, gameObj);
if(isFirst)
outFile << m_cityPrice << ' ' << m_rent << std::endl;
else
outFile << std::endl;
}
}
void Luxor_10::Load(ifstream& InFile){
Card::Load(InFile);
if(isFirst){
int price;
int rent;
InFile >> price >> rent;
m_cityPrice = price;
m_rent = rent;
}
}