-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardM12.cpp
More file actions
118 lines (106 loc) · 2.11 KB
/
Copy pathCardM12.cpp
File metadata and controls
118 lines (106 loc) · 2.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
#include "CardM12.h"
CardM12::CardM12(const CellPosition& pos) : Card(pos) // set the cell position of the card
{
cardNumber = 12; // set the inherited cardNumber data member with the card number (12 here)
}
CardM12::CardM12(const CellPosition& pos, int price, int fees) : Card(pos)
{
if (!alreadyset)
{
this->price = price;
this->fees = fees;
alreadyset = true;
}
cardNumber = 12;
}
bool CardM12::av = true;
bool CardM12::alreadyset = false;
int CardM12::price;
int CardM12::fees;
Player* CardM12::Owner = nullptr;
bool CardM12::isAlreadySaved = false;
int CardM12::GetPrice()
{
return price;
}
int CardM12::GetFees()
{
return fees;
}
void CardM12::SetPrice(int p)
{
price = p;
}
void CardM12::SetFees(int f)
{
fees = f;
}
void CardM12::ReadCardParameters(Grid* pGrid)
{
if (!alreadyset)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("New Card12: Enter the price: ");
price = pIn->GetInteger(pOut);
pOut->ClearStatusBar();
pOut->PrintMessage("Enter the fees: ");
fees = pIn->GetInteger(pOut);
pOut->ClearStatusBar();
alreadyset = true;
}
}
void CardM12::Apply(Grid* pGrid, Player* pPlayer)
{
int w;
if (av)
{
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("Buy? (y/n)");
string buy = pIn->GetSrting(pOut);
pOut->ClearStatusBar();
if ((buy == "y" || buy == "Y") && pPlayer->GetWallet() >= price)
{
av = false;
Owner = pPlayer;
w = Owner->GetWallet();
Owner->SetWallet(w - price);
}
}
else if (pPlayer != Owner)
{
w = pPlayer->GetWallet();
if (w >= fees)
{
pPlayer->SetWallet(w - fees);
}
else
{
pPlayer->SetWallet(0);
}
w = Owner->GetWallet();
Owner->SetWallet(w + fees);
}
}
void CardM12::Save(ofstream& OutFile)
{
if (!isAlreadySaved)
{
OutFile << cardNumber << " " << position.GetCellNum() << " " << GetPrice() << " " << GetFees() << endl;
isAlreadySaved = true;
}
else
{
OutFile << cardNumber << " " << position.GetCellNum() << endl;
}
}
void CardM12::ResetOwnership()
{
av = true;
Owner = nullptr;
alreadyset = false;
}
CardM12::~CardM12(void)
{
}