-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tile.cpp
133 lines (127 loc) · 4.06 KB
/
Tile.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
/*
* Email: sam.lazareanu@gmail.com
* ID: ****6281
* @SamuraiPolix - Samuel Lazareanu
*/
#include "Player.hpp"
#include "Buildable.hpp"
#include "Tile.hpp"
namespace ariel{
ostream& operator<<(std::ostream& os, const Tile& tile){
os << tile.resource << " (" << tile.diceNumber << ") ";
return os;
}
// void Tile::initHexVertices(){
// for (size_t i = 0; i < 6; i++){
// hexVertices[i] = Buildable();
// }
// }
// void Tile::initHexEdges(){
// for (size_t i = 0; i < 6; i++){
// hexEdges[i] = Buildable();
// }
// }
void Tile::setVertexAtPos(size_t pos, BuildableVertex* buildable){
hexVertices[pos] = buildable;
hexVertices[pos]->setPos(pos);
}
void Tile::setEdgeAtPos(size_t pos, BuildableEdge* buildable){
hexEdges[pos] = buildable;
hexEdges[pos]->setPos(pos);
}
void Tile::setResource(ResourceType resource){
this->resource = resource;
}
void Tile::setNumber(size_t number){
this->diceNumber = number;
}
void Tile::setRobber(bool hasRobber) {
this->hasRobber = hasRobber;
}
void Tile::addPlayer(Player& player){
players.push_back(player);
}
void Tile::removePlayer(Player& player){
for (size_t ind = 0; ind < players.size(); ind++){
if (players[ind].getName() == player.getName()){
players.erase(players.begin() + (int)ind);
break; // found the player, no need to continue
}
}
}
ResourceType Tile::getResource() const{
return this->resource;
}
size_t Tile::getNumber() const{
return this->diceNumber;
}
bool Tile::getRobber() const{
return this->hasRobber;
}
vector<Player> Tile::getPlayers() const{
return this->players;
}
BuildableVertex* Tile::getVertex(size_t pos){
return hexVertices[pos];
}
BuildableEdge* Tile::getEdge(size_t pos){
return hexEdges[pos];
}
bool Tile::isVertexOwner(VertexPosition pos, Player& player){
if (hexVertices[pos]->getOwner() != NULL)
return hexVertices[pos]->getOwner()->getName() == player.getName();
else
return false;
}
bool Tile::isEdgeOwner(EdgePosition pos, Player& player){
if (hexEdges[pos]->getOwner() != NULL)
return hexEdges[pos]->getOwner()->getName() == player.getName();
else
return false;
}
bool Tile::hasIndexVertex(size_t index){
for (size_t i = 0; i < 6; i++){
if (hexVertices[i]->getIndex() == index){
return true;
}
}
return false;
}
int Tile::setSettlementAt(VertexPosition pos, Player& player){
#ifdef DEBUG
std::cout << "TYPE: " << hexVertices[pos]->getType() << "\n";
std::cout << "Land: " << this->getResource() << "\n";
std::cout << "NUM: " << this->getNumber() << "\n";
#endif
if (hexVertices[pos]->getType() == BuildableTypes::None){
hexVertices[pos]->setSettlement(player);
// add player to list if is not in it already
if (this->players.size() == 0){
this->players.push_back(player);
}
else{
for (size_t i = 0; i < this->players.size(); i++){
if (this->players[i].getName() == player.getName()){
return 0;
}
}
this->players.push_back(player);
return 0;
}
return 0;
}
return -1;
}
int Tile::setRoadAt(EdgePosition pos, Player& player){
#ifdef DEBUG
std::cout << "TYPE: " << hexEdges[pos]->getType() << "\n";
std::cout << "Land: " << this->getResource() << "\n";
std::cout << "NUM: " << this->getNumber() << "\n";
#endif
if (hexEdges[pos]->getType() == BuildableTypes::None){
hexEdges[pos]->setRoad(player);
return 0;
}
return -1;
}
}