-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardTwelve.cpp
More file actions
118 lines (108 loc) · 3.19 KB
/
Copy pathCardTwelve.cpp
File metadata and controls
118 lines (108 loc) · 3.19 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "CardTwelve.h"
#include "CardNine.h"
#include "CardTen.h"
#include "CardEleven.h"
#include "Player.h"
CardTwelve::CardTwelve(const CellPosition& cellposition) :Card(cellposition)
{
cardNumber = 12;
}
void CardTwelve::ReadCardParameters(Grid* pGrid)
{
}
void CardTwelve::Apply(Grid* pGrid, Player* pPlayer)
{
Card::Apply(pGrid, pPlayer);
CardNine* C9=NULL;
CardTen* C10=NULL;
CardEleven* C11=NULL;
int Preventer = 0; // this variable prevents printing the last message if the Current Player does not have any cards
int MaxPrice;
Output* pOut = pGrid->GetOutput();
Player* NewOwner = pGrid->GetPoorest();
int IndexOfPoorestPlayer = NewOwner->getPlayerNum();
bool Test=true;
if (pPlayer->GetWallet() == NewOwner->GetWallet())
{
pOut->PrintMessage("You are the poorest player");
return;
}
int CommonWallet = pPlayer->GetEqualWallets(); // this variable is used because function IsEqualWallets makes EqualWallet =-1 so we will not be able to get the previous one
bool IsEqual = pPlayer->IsEqualWallets(); // for the same reason mentioned above
if ((IsEqual && (CommonWallet != NewOwner->GetWallet()))||(!IsEqual))
Test = false;
if (Test)
NewOwner = NULL;
if (C9->GetOwner() == pPlayer)
{
MaxPrice = C9->GetCardPrice();
if (C10->GetOwner() == pPlayer)
if (C10->GetCardPrice() > MaxPrice)
MaxPrice = C10->GetCardPrice();
if (C11->GetOwner() == pPlayer)
if (C11->GetCardPrice() > MaxPrice)
MaxPrice = C11->GetCardPrice();
if (NewOwner)
{
if (MaxPrice == C9->GetCardPrice())
{
C9->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card9 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
if (MaxPrice == C10->GetCardPrice())
{
C10->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card10 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
if (MaxPrice == C11->GetCardPrice())
{
C11->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card11 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
}
}
else if (C10->GetOwner() == pPlayer)
{
MaxPrice = C10->GetCardPrice();
if (C11->GetOwner() == pPlayer)
if (C11->GetCardPrice() > MaxPrice)
MaxPrice = C11->GetCardPrice();
if (NewOwner)
{
if (MaxPrice == C10->GetCardPrice())
{
C10->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card10 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
if (MaxPrice == C11->GetCardPrice())
{
C11->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card11 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
}
}
else if (C11->GetOwner() == pPlayer && NewOwner)
{
C11->SetOwner(NewOwner);
pOut->PrintMessage("Now the new owner of Card11 is p(" + to_string(IndexOfPoorestPlayer) + ")");
}
else
{
pOut->PrintMessage("Current Player does not have any cards");
Preventer = 1;
}
if (Test&&Preventer==0)
pOut->PrintMessage("There are Two poorest players have the same amount of money");
}
void CardTwelve::Save(ofstream& OutFile, int Type)
{
if (Type == 2)
{
Card::Save(OutFile, Type);
OutFile << endl;
}
}
void CardTwelve::Load(ifstream& Infile)
{
Card::Load(Infile);
}