-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCardTwelve.cpp
83 lines (71 loc) · 2.45 KB
/
CardTwelve.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
#include "CardNine.h"
#include "CardTen.h"
#include "CardEleven.h"
#include "CardTwelve.h"
CardTwelve::CardTwelve(const CellPosition& pos) : Card(pos) // set the cell position of the card
{
cardNumber = 12; // set the inherited cardNumber data member with the card number
}
CardTwelve::~CardTwelve(void)
{
}
void CardTwelve::Save(ofstream& OutFile) {
OutFile << GetCardNumber() << " " << position.VCell() << " " << position.HCell() << endl;
}
void CardTwelve::Load(ifstream& Infile) {
int vstart = -1, h = -1;
Infile >> vstart >> h;
position.SetHCell(h);
position.SetVCell(vstart);
}
Card* CardTwelve::CopyCard(CellPosition pos)
{
CardTwelve* ptr = new CardTwelve(pos);
return ptr;
}
void CardTwelve::Apply(Grid* pGrid, Player* pPlayer)
{
Card::Apply(pGrid, pPlayer);
//Find out which stations the player owns
int p1=0, p2=0, p3=0;
if(pPlayer == CardNine::GetOwner())
{
p1 = CardNine::GetStationPrice();
}
if (pPlayer == CardTen::GetOwner())
{
p2 = CardTen::GetStationPrice();
}
if (pPlayer == CardEleven::GetOwner())
{
p3 = CardEleven::GetStationPrice();
}
//Check if the player does not have stations
if (p1 == 0 && p2 == 0 && p3 == 0)
{
pGrid->PrintErrorMessage("You don't have any stations to lose ...");
return;
}
//Check if the player has least amount of coins
if (pPlayer->GetPlayerWithLeastMoney(pGrid)==pPlayer)
{
pGrid->PrintErrorMessage("You are the player with the least amount of coins. You don't lose any of your stations ...");
return;
}
//Transfer the most expensive station to the player with the least amount of coins
if (p1 >= p2 && p1 >= p3)
{
CardNine::SetOwner(pPlayer->GetPlayerWithLeastMoney(pGrid));
pGrid->PrintErrorMessage("Now Player NO." + to_string((pPlayer->GetPlayerWithLeastMoney(pGrid))->getPlayerNum ()) + "take station NO.9 from Player NO." + to_string(pPlayer->getPlayerNum()) + " ...");
}
else if (p2 >= p1 && p2 >= p3)
{
CardTen::SetOwner(pPlayer->GetPlayerWithLeastMoney(pGrid));
pGrid->PrintErrorMessage("Now Player NO." + to_string((pPlayer->GetPlayerWithLeastMoney(pGrid))->getPlayerNum()) + "take station NO.10 from Player NO." + to_string(pPlayer->getPlayerNum()) + " ...");
}
else if (p3 >= p1 && p3 >= p2)
{
CardEleven::SetOwner(pPlayer->GetPlayerWithLeastMoney(pGrid));
pGrid->PrintErrorMessage("Now Player NO." + to_string((pPlayer->GetPlayerWithLeastMoney(pGrid))->getPlayerNum()) + "take station NO.11 from Player NO." + to_string(pPlayer->getPlayerNum()) + " ...");
}
}