-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gameplay.cpp
199 lines (151 loc) · 4.88 KB
/
Gameplay.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//Kanellaki Maria Anna - 1115201400060
//Matanis Panagiotis - 1115201400297
#include <iostream>
#include "Gameplay.hpp"
Gameplay::Gameplay(list<Player> player)
{
players = player;
}
void Gameplay::ArrangeTurns() //selection sorting in decreasing order players list by honour
{
list <Player>::iterator max, i;
for (it=players.begin(); it!=players.end(); it++)
{
max = it;
for (i=it; i!=players.end(); i++)
{
if (i->getHonour() > max->getHonour())
max = i;
}
swap(--it, max);
}
}
void Gameplay::startingPhase() //phase1:preparation of each players' cards and printing of his hand and provinces
{
cout << "STARTING PHASE" << endl << endl;
ArrangeTurns();
for (it=players.begin(); it!=players.end(); it++)
{
cout << "Player " << it->getStronghold()->getName() << endl << endl;
it->untapEverything();
it->drawFateCard();
it->revealProvinces();
cout << "Hand: "<<endl;
it->getHand().PrintCards();
cout << "Provinces: "<<endl;
it->getProvinces().PrintCards();
cout << endl;
}
}
void Gameplay::equipPhase() //phase2: each player can equip green cards if he wants
{
cout << "EQUIPMENT PHASE" << endl <<endl;
this->ArrangeTurns();
for (it=players.begin(); it!=players.end(); it++)
{
cout << "Player " << it->getStronghold()->getName() << endl << endl;
if (it->getHand().isEmpty())
cout << "Hand: empty"<<endl;
else
{
cout << "Hand: "<<endl;
it->getHand().PrintCards();
}
if (it->getArmy().getDynDeck().empty())
cout << "Army: empty"<<endl;
else
{
cout << "Army: "<<endl;
it->getArmy().PrintCards();
}
cout <<endl;
it->equipCards();
}
}
void Gameplay::battlePhase() //phase3: each player can attack another's province if he wants
{
string strong, prov;
char ans;
cout << "BATTLE PHASE" << endl <<endl;
this->ArrangeTurns();
list <Player>::iterator it1;
for (it=players.begin(); it!=players.end(); it++)
{
cout << "Player " << it->getStronghold()->getName() << endl << endl;
//attack
cout << "Do you want to attack?"<<endl<<"Enter y for yes, n for no"<<endl;
cin.clear();
cin >> ans;
if (ans != 'y')
continue;
cout << "Prepare cards for attack"<<endl;
it->prepareForBattle();
cout <<"Enter name of player and province to attack to"<<endl; //name of stronghold
cin >> strong;
cin >> prov;
//find target player
for (it1=players.begin(); it1!=players.end(); it1++)
{
if (it1->getStronghold()->getName() == strong)
break;
}
if (it1 == players.end())
{
cout << "Invalid player"<<endl;
return;
}
it->Attack(&*it1, prov);
}
}
void Gameplay::economyPhase() //phase4: each player can buy black cards if he wants
{
cout << "ECONOMY PHASE" << endl <<endl;
this->ArrangeTurns();
for (it=players.begin(); it!=players.end(); it++)
{
cout << "Player " << it->getStronghold()->getName() << endl << endl;
it->getProvinces().PrintCards();
it->buyCards();
}
}
void Gameplay::finalPhase() //phase5: discarding extra hand cards and printing game stats
{
cout << "FINAL PHASE" << endl <<endl;
this->ArrangeTurns();
for (it=players.begin(); it!=players.end(); it++)
{
cout <<"Players remaining: "<<endl;
cout << "Player " << it->getStronghold()->getName() << endl;
it->discardSurplusFateCards();
}
//print game stats
cout << "Stats: "<<endl;
int count=1;
for (it=players.begin(); it!=players.end(); it++)
{
cout << "Player " << count << endl;
it->PrintPlayerStats();
cout << endl;
count++;
}
}
Player *Gameplay::checkWinningCondition() //if someone won returns a pointer to that player else returns null
{ //prints if someone lost and removes him from the list
for (it=players.begin(); it!=players.end(); it++)
{
if (!it->getNumberOfProvinces())
{
cout << "Player "<<it->getStronghold()->getName()<<"lost." << endl;
players.remove(*it);
cout << players.size() <<"players remaining." << endl;
it=players.begin();
}
}
if (players.size() == 1)
return &*players.begin();
return nullptr;
}
Gameplay::~Gameplay()
{
players.clear();
}