-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tile.hpp
78 lines (69 loc) · 3.26 KB
/
Tile.hpp
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
/*
* Email: sam.lazareanu@gmail.com
* ID: ****6281
* @SamuraiPolix - Samuel Lazareanu
*/
#pragma once
#include "Types.hpp"
// #include "Player.hpp"
// #include "Buildable.hpp"
#include <vector>
#include <iostream>
using std::vector, std::ostream;
namespace ariel {
class BuildableEdge;
class BuildableVertex;
class Player;
class Tile
{
// private members
ResourceType resource; // the resource the tile gives
size_t diceNumber; // number on tile that gives resources to players when rolled
bool hasRobber; // if there is a robber on the tile (no resources are given when rolled)
vector<Player> players; // the players that have a settlement or city on the tile (they get resources when the dice number matches the tile)
BuildableVertex* hexVertices[6]; // the vertices of the tile - can be settlements, cities or nothing
BuildableEdge* hexEdges[6]; // The edges of the tile - can be roads or nothing
size_t x, y; // the position of the tile on the board
// private methods
// void initHexVertices();
// void initHexEdges();
public:
Tile() : x(0), y(0), resource(ResourceType::Desert), diceNumber(0), hasRobber(false) {};
Tile(size_t _x, size_t _y, ResourceType _resource, size_t _number) : x(_x), y(_y), resource(_resource), diceNumber(_number), hasRobber(false) {};
~Tile() = default;
void setResource(ResourceType resource);
void setNumber(size_t number);
void setRobber(bool hasRobber);
void addPlayer(Player& player);
void removePlayer(Player& player);
friend ostream& operator<<(ostream& os, const Tile& tile);
void setVertexAtPos(size_t pos, BuildableVertex* buildable);
void setEdgeAtPos(size_t pos, BuildableEdge* buildable);
/*
* Sets the vertex at the given position to a settlement.
* Returns 0 if the vertex was empty and the settlement was placed successfully.
* Returns -1 if the vertex is already taken.
*/
int setSettlementAt(VertexPosition pos, Player& player);
/*
* Sets the edge at the given position to a road.
* Returns 0 if the edge was empty and the road was placed successfully.
* Returns -1 if the edge is already taken.
* @note: This doesn't check if the player has a building (settlement, city or road) near
* - this should be checked in the Board class.
*/
int setRoadAt(EdgePosition pos, Player& player);
ResourceType getResource() const;
size_t getNumber() const;
bool getRobber() const;
vector<Player> getPlayers() const;
BuildableVertex* getVertex(size_t pos);
BuildableEdge* getEdge(size_t pos);
bool isVertexOwner(VertexPosition pos, Player& player);
bool isEdgeOwner(EdgePosition pos, Player& player);
bool hasIndexVertex(size_t index);
bool hasIndexEdge(size_t index);
size_t getX() const {return x;};
size_t getY() const {return y;};
};
}