-
Notifications
You must be signed in to change notification settings - Fork 1
/
CardSix.cpp
75 lines (61 loc) · 2.06 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
#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 (6 here)
}
Card* CardSix::GetCopy(const CellPosition& pos)
{
return new CardSix(pos);
}
void CardSix::ReadCardParameters(Grid* pGrid)
{
// 1- Get a Pointer to the Input / Output Interfaces from the Grid
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// 2- Read an Integer from the user using the Input class and set the CellToMoveTo parameter with it
pOut->PrintMessage("New CardSix: Click on the cell to move to");
CellToMoveTo = pIn->GetCellClicked();
// 3- Validation to click inside the grid area
if (!CellToMoveTo.IsValidCell() || CellToMoveTo.GetCellNum() == this->GetPosition().GetCellNum())
{
int x, y;
pOut->PrintMessage("You clicked on an invalid cell, Click to continue.");
pIn->GetPointClicked(x, y);
}
// 3- Clear the status bar
pOut->ClearStatusBar();
}
void CardSix::Apply(Grid* pGrid, Player* pPlayer)
{
Card::Apply(pGrid, pPlayer); //Call Apply() of the base class Card to print the message that you reached this card number
if (!(!CellToMoveTo.IsValidCell() || CellToMoveTo.GetCellNum() == this->GetPosition().GetCellNum()))
{
int newposition = CellToMoveTo.GetCellNum() - (pPlayer->GetCell()->GetCellPosition().GetCellNum());
pPlayer->Move(pGrid, newposition);
pPlayer->SetTurnCount(pPlayer->GetTurnCount() - 1);
}
}
void CardSix::Save(ofstream& outFile, ObjectType ObjType)
{
if (ObjType == Cards)
{
// Calling the parent class save function that saves the type and cell to the file
Card::Save(outFile, ObjType);
outFile << this->CellToMoveTo.GetCellNum() << std::endl;
}
}
void CardSix::Load(ifstream& InFile) {
Card::Load(InFile);
int CellNum;
InFile >> CellNum;
this->CellToMoveTo = CellPosition::GetCellPositionFromNum(CellNum);
}
CardSix:: ~CardSix()
{
}
bool CardSix::CheckInputValidity()
{
if (!CellToMoveTo.IsValidCell() || CellToMoveTo.GetCellNum() == this->GetPosition().GetCellNum())
return 0;
return 1;
}