-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCardEight.cpp
75 lines (60 loc) · 2.13 KB
/
CardEight.cpp
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
#include "CardEight.h"
CardEight::CardEight(const CellPosition & pos) : Card(pos) // set the cell position of the card
{
cardNumber = 8; // set the inherited cardNumber data member with the card number
}
CardEight::~CardEight(void)
{
}
void CardEight::Save(ofstream& OutFile) {
OutFile << GetCardNumber() << " " << position.VCell() << " " << position.HCell() << " " << GoOut << endl;
}
void CardEight::Load(ifstream& Infile) {
int vstart = -1, h = -1;
Infile >> vstart >> h>>GoOut;
position.SetHCell(h);
position.SetVCell(vstart);
}
void CardEight::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("New CardEight : Enter The amount of coins needed to go out of the prison ...");
GoOut = pIn->GetInteger(pOut);
//Check if the prison release fee is valid
while (GoOut < 1)
{
pOut->PrintMessage("You entered an invalid Number: Plase enter The amount of coins needed to go out of the prison ...");
GoOut = pIn->GetInteger(pOut);
}
// 3- Clear the status bar
pOut->ClearStatusBar();
}
Card* CardEight::CopyCard(CellPosition pos)
{
CardEight* ptr = new CardEight(pos);
ptr->GoOut = GoOut;
return ptr;
}
void CardEight::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);
Output *pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("Now you have to choose 1- Pay " + to_string(GoOut) + " coins and continue playing 2- Don't play for 3 turns ...");
int x = pIn->GetInteger(pOut);
while (x != 1&&x!=2)
{
pOut->PrintMessage("Incorrect selection, please choose again: 1- Pay " + to_string(GoOut) + " coins and continue playing 2- Don't play for 3 turns...");
GoOut = pIn->GetInteger(pOut);
}
// 2- Decrement the wallet of pPlayer by the GoOut data member of CardEight
if(x==1)
pPlayer->SetWallet(pPlayer->GetWallet() - GoOut);
// 3- Make the turnskip of the player who stood on the card = 3
if(x==2)
pPlayer->setTurnsToSkip(3);
pOut->ClearStatusBar();
}