-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCardTwelve.cpp
101 lines (78 loc) · 2.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "CardTwelve.h"
#include <iostream>
using namespace std;
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 (12 here)
}
CardTwelve::~CardTwelve(void)
{
}
void CardTwelve::ReadCardParameters(Grid* pGrid)
{
// No parameters will be read
}
Card* CardTwelve::Copy(Card* pCard) {
CellPosition pos;
CardTwelve* copy = new CardTwelve(pos);
return copy;
}
void CardTwelve::Apply(Grid* pGrid, Player* pPlayer)
{
CellPosition invalidPos(-1, -1);
card9 = new CardNine(invalidPos);
card10 = new CardTen(invalidPos);
card11 = new CardEleven(invalidPos);
int maxValue, maxIndex;
int prices[3] = { -1,-1,-1 };
// Getting poorest player on the grid (not including currPlayer)
Player* poorestPlayer = pGrid->getPoorestPlayer();
if (card9->getOwner() != pPlayer)
card9 = NULL;
if (card10->getOwner() != pPlayer)
card10 = NULL;
if (card11->getOwner() != pPlayer)
card11 = NULL;
if (!(card9 || card10 || card11)) {
return;
}
if (card9)
prices[0] = card9->getPrice();
if (card10)
prices[1] = card10->getPrice();
if (card11)
prices[2] = card11->getPrice();
maxValue = prices[0];
maxIndex = 0;
for (int i = 1; i < 3; i++) {
if (prices[i] > maxValue) {
maxIndex = i;
maxValue = prices[i];
}
}
switch (maxIndex) {
case 0:
card9->setOwner(poorestPlayer);
pGrid->PrintErrorMessage("You just lost your most expensive card (Card 9) to player number " + to_string(poorestPlayer->getPlayerNum()) + "....");
break;
case 1:
card10->setOwner(poorestPlayer);
pGrid->PrintErrorMessage("You just lost your most expensive card (Card 10) to player number " + to_string(poorestPlayer->getPlayerNum()) + "....");
break;
case 2:
card11->setOwner(poorestPlayer);
pGrid->PrintErrorMessage("You just lost your most expensive card (Card 11) to player number " + to_string(poorestPlayer->getPlayerNum()) + "....");
break;
}
delete card9;
delete card10;
delete card11;
}
void CardTwelve::Save(ofstream& OutFile)
{
Card::Save(OutFile);
}
void CardTwelve::Load(ifstream& InFile)
{
Card::Load(InFile);
}