-
Notifications
You must be signed in to change notification settings - Fork 2
/
CardTwo.cpp
56 lines (41 loc) · 1.2 KB
/
CardTwo.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
#include "CardTwo.h"
#include "Ladder.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(void)
{
}
void CardTwo::ReadCardParameters(Grid* pGrid)
{
}
void CardTwo::Apply(Grid* pGrid, Player* pPlayer)
{
Card::Apply(pGrid, pPlayer);
// get cellposition of the player
CellPosition currentCellPosition = pPlayer->GetCell()->GetCellPosition();
// get next ladder after the position
Ladder* nextLadder = pGrid->GetNextLadder(currentCellPosition);
// if exist
if (nextLadder != NULL) {
// move player the end of it (or to start and take it)
pGrid->UpdatePlayerCell(pPlayer, nextLadder->GetEndPosition());
// if the is any (Card, Ladder, Snake) take it
if (pPlayer->GetCell()->GetGameObject()) {
pPlayer->GetCell()->GetGameObject()->Apply(pGrid, pPlayer);
}
}
}
Card* CardTwo::GetCopy(CellPosition& Pos)
{
return new CardTwo(Pos);
}
void CardTwo::Save(ofstream& OutFile)
{
OutFile << this->GetCardNumber() << "\t" << this->position.GetCellNum() << "\n";
}
void CardTwo::Load(ifstream& Infile, Grid* pGrid)
{
pGrid->AddObjectToCell(this);
}