Skip to content

Commit b1d40ab

Browse files
committed
Extended GamePiece with getCoordinate and getBoard
1 parent 9997dde commit b1d40ab

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/GamePiece.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class GamePiece {
1414
GamePiece(GamePiece&) = delete;
1515
virtual ~GamePiece();
1616
virtual GamePiece& operator=(GamePiece&) = delete;
17+
18+
Coordinate getCoordinates() const;
19+
GameBoard& getBoard();
20+
const GameBoard& getBoard() const;
1721
};
1822

1923
class ResourceTile : public GamePiece {

src/GamePiece.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ GamePiece::~GamePiece() {
1414

1515
}
1616

17+
Coordinate GamePiece::getCoordinates() const {
18+
for(auto& it : board.getPieces()) {
19+
if(it.second.get() == this) {
20+
return it.first;
21+
}
22+
}
23+
throw runtime_error("This GamePiece does not exist on the board it holds a reference to.");
24+
}
25+
26+
GameBoard& GamePiece::getBoard() {
27+
return board;
28+
}
29+
30+
const GameBoard& GamePiece::getBoard() const {
31+
return board;
32+
}
33+
1734
ResourceTile::ResourceTile(GameBoard& board, Type type, unsigned short diceValue) : GamePiece(board), type(type), diceValue(diceValue) {
1835
if(type != WOOD && type != SHEEP && type != ORE && type != BRICK && type != GRAIN && type != DESERT) {
1936
throw runtime_error("Invalid resource tile type");

0 commit comments

Comments
 (0)