-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayer.cpp
More file actions
118 lines (97 loc) · 1.81 KB
/
Copy pathplayer.cpp
File metadata and controls
118 lines (97 loc) · 1.81 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 "Player.h"
#include "Country.h"
#include <string>
#include <iostream>
using namespace std;
Player::Player()
{
}
Player::Player(Colours colour, string playername)
{
colour = colour;
name = playername;
}
Player::Player(int id, string playername)
{
name = playername;
playerID = id;
_colour = Blue;
_renforcements = 10;
_armiesOwned = 10;
_battlesWon = 10;
}
Player::Player(Colours c, int r, int a, int b)
{
_colour = c;
_renforcements = r;
_armiesOwned = a;
_battlesWon = b;
}
Player::Player(string name, int color, int turnOrder)
{
this->name = name;
this->color = color;
this->turnOrder = turnOrder;
}
int Player::getID()
{
return playerID;
}
void Player::AddCountry(Country* c)
{
_countriesOwned.push_back(c);
Notify(this);
}
void Player::RemoveCountry(Country* c)
{
for (int i = 0; i < int(_countriesOwned.size()); i++)
{
if (_countriesOwned[i] == c)
{
_countriesOwned.erase(_countriesOwned.begin() + i);
break;
}
}
Notify(this);
}
void Player::AddContinent(Continent* c)
{
_continentsOwned.push_back(c);
Notify(this);
}
void Player::RemoveContinent(Continent* c)
{
for (int i = 0; i < int(_continentsOwned.size()); i++)
{
if (_continentsOwned[i] == c)
{
_continentsOwned.erase(_continentsOwned.begin() + i);
break;
}
}
Notify(this);
}
void Player::Notify(Player* p)
{
//cout << "Notify" << endl;
for (size_t i = 0; i < _observers.size(); i++)
{
//TODO check if observer is of type player.
_observers[i]->Update(p);
}
}
bool Player::hasCountry(string country){
for (size_t i = 0; i < _countriesOwned.size(); i++){
if (_countriesOwned[i]->getName() == country)
return true;
}
return false;
}
bool Player::canPlay(){
for (int i = 0; i < _countriesOwned.size(); i++)
{
if (_countriesOwned[i]->numberOfPieces > 1)
return true;
}
return false;
}