-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardNine.cpp
More file actions
145 lines (136 loc) · 2.89 KB
/
CardNine.cpp
File metadata and controls
145 lines (136 loc) · 2.89 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
#include "CardNine.h"
int CardNine::CardPrice=0;
int CardNine::Fees=0;
int CardNine::NumberOfCards = 0;
Player* CardNine::Owner=nullptr;
bool CardNine::IsSaved = false;
bool CardNine::IsRead = false;
CardNine::CardNine(const CellPosition& cellposition) :Card(cellposition)
{
NumberOfCards++;
cardNumber = 9;
}
void CardNine::ReadCardParameters(Grid* pGrid)
{
if (Fees==0) {
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pGrid->PrintErrorMessage("Card Nine : Station 1 , click to continue..");
pOut->PrintMessage("Enter its Price : ");
int t;
do
{
t = pIn->GetInteger(pOut);
if (t > 0)
{
CardPrice = t;
}
else pOut->PrintMessage("Invalid Price ! please try again.");
} while (t <= 0);
pOut->PrintMessage("Enter its Fees : ");
do
{
t = pIn->GetInteger(pOut);
if (t > 0)
{
Fees = t;
}
else pOut->PrintMessage("Invalid Fees value ! please try again.");
} while (t <= 0);
pOut->ClearStatusBar();
}
}
void CardNine::Apply(Grid* pGrid, Player* pPlayer)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
if (!Owner)
{
Card::Apply(pGrid, pPlayer);
pGrid->PrintErrorMessage("This is station 1 , Price : " + to_string(CardPrice) + " Fees : " + to_string(Fees) + " click to continue...");
pOut->PrintMessage("Would you like to purchase ? Yes(y) or No(n)");
string t;
do
{
t = pIn->GetSrting(pOut);
if (t == "y")
{
if (pPlayer->GetWallet() >= CardPrice) {
pPlayer->SetWallet(pPlayer->GetWallet() - CardPrice);
Owner = pPlayer;
pOut->PrintMessage("Purchase complete .");
}
else
{
pGrid->PrintErrorMessage("Insufficient wallet, click to continue.. ");
}
}
else if (t != "n") {
pOut->PrintMessage("Invalid input ! please try again. ");
}
} while (t!="y" && t!="n");
}
else
{
if (Owner != pPlayer)
{
pOut->PrintMessage("Stepped on a card owned by p(" + to_string(Owner->getPlayerNum()) + ") pay : " + to_string(Fees));
if(Fees<pPlayer->GetWallet())
Owner->SetWallet(Owner->GetWallet() + Fees);
else
Owner->SetWallet(Owner->GetWallet() + pPlayer->GetWallet());
pPlayer->SetWallet(pPlayer->GetWallet() - Fees);
}
}
}
Player* CardNine::GetOwner()
{
return Owner;
}
void CardNine::SetOwner(Player* pNew)
{
Owner = pNew;
}
int CardNine::GetCardPrice()
{
return CardPrice;
}
void CardNine::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
if (!IsSaved)
{
OutFile << CardPrice << " " << Fees;
IsSaved = true;
}
OutFile << endl;
}
}
void CardNine::Load(ifstream& Infile)
{
Card::Load(Infile);
if (!IsRead)
{
Infile >> CardPrice >> Fees;
IsRead = true;
}
}
void CardNine::SetIsSavedF()
{
IsSaved = false;
}
void CardNine::SetIsReadF()
{
IsRead = false;
}
CardNine::~CardNine() {
NumberOfCards--;
if (NumberOfCards == 0)
{
Fees = 0;
CardPrice = 0;
Owner = nullptr;
}
}