-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardTen.cpp
More file actions
150 lines (137 loc) · 2.88 KB
/
CardTen.cpp
File metadata and controls
150 lines (137 loc) · 2.88 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
149
150
#include "CardTen.h"
int CardTen::CardPrice = 0;
int CardTen::Fees = 0;
int CardTen::NumberOfCards = 0;
Player* CardTen::Owner = nullptr;
bool CardTen::IsSaved = false;
bool CardTen::IsRead = false;
CardTen::CardTen(const CellPosition& cellposition) :Card(cellposition)
{
NumberOfCards++;
cardNumber = 10;
}
void CardTen::ReadCardParameters(Grid* pGrid)
{
if (Fees==0) {
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pGrid->PrintErrorMessage("Card Ten : Station 2 , 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 CardTen::Apply(Grid* pGrid, Player* pPlayer)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
if (!Owner)
{
Card::Apply(pGrid, pPlayer);
pGrid->PrintErrorMessage("This is station 2 , 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* CardTen::GetOwner()
{
return Owner;
}
void CardTen::SetOwner(Player* pNew)
{
Owner = pNew;
}
int CardTen::GetCardPrice()
{
return CardPrice;
}
void CardTen::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
if (!IsSaved)
{
OutFile << CardPrice << " " << Fees;
IsSaved = true;
}
OutFile << endl;
}
}
void CardTen::Load(ifstream& Infile)
{
Card::Load(Infile);
if (!IsRead)
{
Infile >> CardPrice >> Fees;
IsRead = true;
}
}
void CardTen::SetIsSavedF()
{
IsSaved = false;
}
void CardTen::SetIsReadF()
{
IsRead = false;
}
CardTen::~CardTen()
{
NumberOfCards--;
if (NumberOfCards == 0)
{
Fees = 0;
CardPrice = 0;
Owner = nullptr;
}
}