-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCardSix.cpp
47 lines (40 loc) · 1.67 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
#include "CardSix.h"
CardSix::CardSix(CellPosition& p) :Card(p) {
cardNumber= 6;
}
void CardSix::ReadCardParameters(Grid * pGrid) {
pGrid->GetOutput()->PrintMessage("Please, Click on the destination cell...."); //read the cell to move to
cellToMove = pGrid->GetInput()->GetCellClicked();
CardSix* ptr = dynamic_cast<CardSix*>(pGrid->GetCell(cellToMove.VCell(), cellToMove.HCell())->GetGameObject());
while (cellToMove.GetCellNum() == position.GetCellNum() || ptr)
{
pGrid->GetOutput()->PrintMessage("The destination cell can't be a CardSix, click on another!");
cellToMove = pGrid->GetInput()->GetCellClicked();
ptr = dynamic_cast<CardSix*>(pGrid->GetCell(cellToMove.VCell(), cellToMove.HCell())->GetGameObject());
}
pGrid->GetOutput()->ClearStatusBar();
}
Card* CardSix::CopyCard(CellPosition pos)
{
CardSix* ptr = new CardSix(pos);
ptr->cellToMove = cellToMove;
return ptr;
}
void CardSix::Save(ofstream& OutFile) {
OutFile << GetCardNumber() << " " << position.VCell() << " " << position.HCell() << " " << cellToMove.GetCellNum() << endl;
}
void CardSix::Load(ifstream& Infile) {
int vstart = -1, h = -1;
int cellNum = cellToMove.GetCellNum();
Infile >> vstart >> h >> cellNum;
cellToMove = CellPosition(cellNum);
position.SetHCell(h);
position.SetVCell(vstart);
}
void CardSix::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- moving the player to the cell chosen in the design mode
pGrid->PrintErrorMessage("You go to cell number " +to_string(cellToMove.GetCellNum()) + ", click to continue...");
pGrid->UpdatePlayerCell(pPlayer, cellToMove);
}