-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardNine.cpp
More file actions
120 lines (99 loc) · 3.11 KB
/
CardNine.cpp
File metadata and controls
120 lines (99 loc) · 3.11 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
#include "CardNine.h"
int CardNine::price = 0;
int CardNine::fees = 0;
Player* CardNine::CardOwner = NULL;
CardNine::CardNine(const CellPosition& pos) : Card(pos) // set the cell position of the card
{
cardNumber = 9; // set the inherited cardNumber data member with the card number (1 here)
}
CardNine::~CardNine(void)
{
}
void CardNine::ReadCardParameters(Grid* pGrid)
{
///TODO: Implement this function as mentiNined in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) (numbered below) to implement this function ==
// 1- Get a Pointer to the Input / Output Interfaces from the Grid
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// 2- Get parameter of CardNine
// 1-1 price 1-2 fees
if (price == 0 && fees == 0) {
pOut->PrintMessage("Enter price of the cell");
price = pIn->GetInteger(pOut);
while (price <= 0)
{
pOut->PrintMessage("invalid::renter the price");
price = pIn->GetInteger(pOut);
}
pOut->PrintMessage("Enter Fees payed to owner of the cell");
fees = pIn->GetInteger(pOut);
while (fees <= 0)
{
pOut->PrintMessage("invalid::renter the price");
fees = pIn->GetInteger(pOut);
}
// 3- Clear the status bar
this->setPrice(price);
pOut->ClearStatusBar();
}
}
///////////////////////////////////////////////Fatma
//////////////////////////////////////////////////////
////////////////////////////////////////////////////
/////////////////////////////////////////////////////
void CardNine::Apply(Grid* pGrid, Player* pPlayer)
{
///TODO: Implement this function as mentiNined in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) (numbered below) to implement this function ==
Input* inp = pGrid->GetInput();
Output* out = pGrid->GetOutput();
// 1- Call Apply() of the base class Card to print the message that you reached this card number
Card::Apply(pGrid, pPlayer);
if (CardOwner == NULL)
{
out->PrintMessage("do you want to buy this cell?y/n");
string x;
x=inp->GetSrting(out) ;
if(x=="y"||x=="Y")
{
int w =( pPlayer->GetWallet()-price);
if(w<0)
{
out->PrintMessage("you dont have enough money,click anywhere to continue");
inp->GetCellClicked();
}
else {
pPlayer->SetWallet(w);
CardOwner = pPlayer;
pPlayer->SetAsOwner(this);
}
}
}
else {
if (pPlayer == CardOwner) {
out->PrintMessage("the owner of the card,click anywhereto continue");
inp->GetCellClicked();
}
else {
pPlayer->SetWallet(pPlayer->GetWallet() - fees);
if(fees<= pPlayer->GetWallet())
CardOwner->SetWallet( fees+ CardOwner->GetWallet());
else
CardOwner->SetWallet(pPlayer->GetWallet() + CardOwner->GetWallet());
}
}
out->ClearStatusBar();
}
void CardNine::SaveCardParameter(ofstream& OutFile)
{
OutFile << ' ' << fees << ' ' << price << endl;
}
void CardNine::Load(ifstream& Infile)
{
string f, p;
getline(Infile, f, ' ');
getline(Infile, p, '\n');
fees = stoi(f);
price = stoi(p);
}