-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardSix.cpp
84 lines (57 loc) · 1.96 KB
/
CardSix.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
76
77
78
79
80
81
82
83
84
#include "CardSix.h"
CardSix::CardSix(const CellPosition& pos) : Card(pos) // set the cell position of the card
{
cardNumber = 6; // set the inherited cardNumber data member with the card number (1 here)
}
CardSix::~CardSix(void)
{
}
void CardSix::ReadCardParameters(Grid* pGrid)
{
///TODO: Implement this function as mentioned 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
// 1- Get a Pointer to the Input / Output Interfaces from the Grid
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// reads the cell that the player will move to after standing on the card
pOut->PrintMessage("New CardSix: Click on the cell to move to ...");
CellToMoveTo = pIn->GetCellClicked();
while (CellToMoveTo.GetCellNum() == this->position.GetCellNum()||!CellToMoveTo.IsValidCell())
{
pOut->PrintMessage("You cannot choose this cell, Try Again");
CellToMoveTo = pIn->GetCellClicked();
}
// 3- Clear the status bar
pOut->ClearStatusBar();
}
void CardSix::Apply(Grid* pGrid, Player* pPlayer)
{
Output* pOut = pGrid->GetOutput();
// Call Apply() of the base class Card to print the message that you reached this card number
Card::Apply(pGrid, pPlayer);
pOut->ClearStatusBar();
pGrid->PrintErrorMessage("Move to cell number : " + to_string(CellToMoveTo.GetCellNum())+" click to continue");
// Move the player
pGrid->UpdatePlayerCell(pPlayer, CellToMoveTo);
GameObject* pObj = pPlayer->GetCell()->GetGameObject();
if(pObj)
{
pObj->Apply(pGrid, pPlayer);
}
}
void CardSix::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
OutFile << this->CellToMoveTo.GetCellNum() << endl;
}
}
void CardSix::Load(ifstream& Infile)
{
Card::Load(Infile);
int CellNum;
Infile >> CellNum;
CellToMoveTo = CellPosition::GetCellPositionFromNum(CellNum);
}