-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCardTwo.cpp
More file actions
84 lines (69 loc) · 2.55 KB
/
CardTwo.cpp
File metadata and controls
84 lines (69 loc) · 2.55 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
#include "CardTwo.h"
CardTwo::CardTwo(const CellPosition& pos) : Card(pos) // set the cell position of the card
{
cardNumber = 2; // set the inherited cardNumber data member with the card number (2 here)
}
CardTwo::CardTwo(const CellPosition& pos, Card* c) : Card(pos)
{
CardTwo* sc = dynamic_cast<CardTwo*>(c);
cardNumber = 2; // set the inherited cardNumber data member with the card number (1 here)
this->walletAmount = sc->walletAmount;
}
CardTwo::~CardTwo(void)
{
}
void CardTwo::ReadCardParameters(Grid* pGrid)
{
// 1- Get a Pointer to the Input / Output Interfaces from the Grid
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("CardTwo: Enter its wallet amount ...");
// 2- Read an Integer from the user using the Input class and set the walletAmount parameter with it
// Don't forget to first print to a descriptive message to the user like:"New CardTwo: Enter its wallet amount ..."
walletAmount = pIn->GetInteger(pOut);//the user might enter invalid amount
if (!IsValidCard())//checks if the entered amount is valid
pGrid->PrintErrorMessage("Error: Invalid wallet amount ...");
// [ Note ]:
// In CardTwo, the only parameter of CardTwo is the "walletAmount" value to increase player's wallet
// Card parameters are the inputs you need to take from the user in the time of adding the Card in the grid
// to be able to perform his Apply() action
// 3- Clear the status bar
pOut->ClearStatusBar();
}
bool CardTwo::IsValidCard() const
{
if (walletAmount > 0)//checks if the entered amount is positive integer
return true;
else
return false;
}
void CardTwo::Save(ofstream& save, ObjectType T)
{
if (T != Cards) return;
save << cardNumber << " " << position.GetCellNum() << " " << walletAmount << "\n";
}
void CardTwo::Read(ifstream& load)
{
int cellpos, value;
load >> cellpos >> value;
position = CellPosition::GetCellPositionFromNum(cellpos);
walletAmount = value;
}
void CardTwo::EditParameters(Grid* pGrid)
{
int prevwalletAmount = walletAmount;
ReadCardParameters(pGrid);
if (!IsValidCard())
{
walletAmount = prevwalletAmount;
return;
}
pGrid->PrintErrorMessage("Card Edited Successfully ...");
}
void CardTwo::Apply(Grid* pGrid, Player* pPlayer)
{
// 1- Call Apply() of the base class Card to print the message that you reached this card number
Card::Apply(pGrid, pPlayer);
// 2- Increment the wallet of pPlayer by the walletAmount data member of CardTwo
pPlayer->SetWallet(pPlayer->GetWallet() + walletAmount);
}