Skip to content

Commit 24d27eb

Browse files
committed
Merge pull request #32 from Databean/player_turn
Player turn
2 parents 26b1eee + 0621d88 commit 24d27eb

File tree

6 files changed

+87
-6
lines changed

6 files changed

+87
-6
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>warsofcatan</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>

include/GameBoard.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class GameBoard {
3838
std::vector<std::unique_ptr<Player>> players;
3939
Coordinate robber;
4040

41+
int currentTurn;
42+
43+
int maxVictoryPoints;
4144

4245
void addResource(int x, int y, resourceType res, int val);
4346
bool checkRolls(int* rolls);
@@ -77,7 +80,11 @@ class GameBoard {
7780

7881
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
7982

83+
void endTurn();
84+
Player& getCurrentPlayer() const;
8085

86+
int getMaxVictoryPoints();
87+
void setMaxVictoryPoints(int maxVicPts);
8188

8289
const std::shared_ptr<Road> getRoad(Coordinate start, Coordinate end) const;
8390
const std::vector<std::shared_ptr<Road>>& getRoads(Coordinate loc) const;

include/GameController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ class GameController {
2929
GameController(GameBoard&, GameView& view);
3030
~GameController();
3131

32+
bool nextTurn(ScreenCoordinate);
3233
bool handleBoardEvent(ScreenCoordinate);
3334
bool handleRoadButtonEvent(ScreenCoordinate);
3435
bool handleSettlementButtonEvent(ScreenCoordinate);
3536
bool handlePlayerClick(ScreenCoordinate, Player&);
3637
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
3738
};
3839

39-
#endif
40+
#endif

src/GameBoard.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
4040
players.push_back(std::unique_ptr<Player>(new Player(*this, name)));
4141
}
4242

43+
currentTurn = 0;
44+
4345
std::srand(std::time(0));
4446

4547
const static vector<resourceType> boardResources {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP};
@@ -126,6 +128,7 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
126128
if(!isValidBoard()) {
127129
throw std::runtime_error("Board is invalid.");
128130
}
131+
currentTurn = 0;
129132
}
130133

131134
/**
@@ -253,6 +256,8 @@ GameBoard::GameBoard(istream& in) {
253256
if(!isValidBoard()) {
254257
throw std::runtime_error("Board is invalid.");
255258
}
259+
260+
currentTurn = 0; //have to update <<--
256261
}
257262

258263
/**
@@ -307,6 +312,50 @@ ResourceTile& GameBoard::getResourceTile(Coordinate location) const
307312
return *(resources.find(location)->second);
308313
}
309314

315+
316+
/**
317+
* Ends current players turn and moves the current turn marker
318+
*/
319+
void GameBoard::endTurn()
320+
{
321+
if(getCurrentPlayer().getVictoryPoints() >= getMaxVictoryPoints())
322+
std::cout<<"GG Bitches";
323+
324+
currentTurn++;
325+
if(currentTurn >= getNoOfPlayers())
326+
currentTurn = 0;
327+
328+
startTurn();
329+
}
330+
331+
/**
332+
* @return reference to the current Player
333+
*/
334+
Player& GameBoard::getCurrentPlayer() const
335+
{
336+
return *players[currentTurn];
337+
}
338+
339+
340+
/**
341+
* @return The no of Victory points needed to win the game
342+
*/
343+
int GameBoard::getMaxVictoryPoints()
344+
{
345+
return maxVictoryPoints;
346+
}
347+
348+
349+
/**
350+
* Sets the no of victory points needed to win the game
351+
* @param maxVicPts victory points needed to win the game
352+
*/
353+
void GameBoard::setMaxVictoryPoints(int maxVicPts)
354+
{
355+
maxVictoryPoints = maxVicPts;
356+
}
357+
358+
310359
/**
311360
* Finds settlements neighboring a particular coordinate.
312361
* @param location The location to search the neighbors of.
@@ -481,7 +530,7 @@ bool GameBoard::PlaceRoad(Coordinate start, Coordinate end, Player& Owner) {
481530
roads[start].push_back(newRoad);
482531
roads[end].push_back(newRoad);
483532

484-
startTurn();
533+
// startTurn();
485534

486535
return true;
487536
}

src/GameController.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
*/
1717
GameController::GameController(GameBoard& model, GameView& view) : model(model), view(view), placingRoads(false), placingCities(false) ,lastCoordClick(-100, -100) {
1818
using namespace std::placeholders;
19-
19+
20+
21+
view.addElement(makeViewButtonColor(std::bind(&GameController::nextTurn, this, _1), {{0, 0.2}, {0.1, 0.3}}, std::make_tuple(0.f, 0.f, 1.f)));
22+
view.addElement(makeViewButtonColor(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.1}}, std::make_tuple(1.f, 0.f, 0.f)));
23+
view.addElement(makeViewButtonColor(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0, 0.1}, {0.1, 0.2}}, std::make_tuple(0.f, 1.0f, 0.f)));
24+
2025
auto font = "resources/TypeWritersSubstitute-Black.ttf";
2126
auto fontSize = 50;
2227

23-
view.addElement(makeViewButtonText(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.1}}, font, fontSize, "Road"));
24-
view.addElement(makeViewButtonText(std::bind(&GameController::handleSettlementButtonEvent, this, _1), {{0, 0.1}, {0.1, 0.2}}, font, fontSize, "Settlement"));
25-
28+
2629
auto playerTopY = 0.9;
2730
for(auto i = 0; i < model.getNoOfPlayers(); i++) {
2831
auto width = 0.2;
@@ -31,6 +34,7 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
3134
playerTopY -= 0.05;
3235
}
3336

37+
3438
view.addElement(makeViewButton(std::bind(&GameController::handleBoardEvent, this, _1), {{0, 0}, {1, 1}}));
3539
}
3640

@@ -41,6 +45,15 @@ GameController::~GameController() {
4145

4246
}
4347

48+
/**
49+
* calls a function to advance turn, check for victory and roll dice
50+
*/
51+
bool GameController::nextTurn(ScreenCoordinate) {
52+
model.endTurn();
53+
return true;
54+
}
55+
56+
4457
/**
4558
* Handles a click that is actually on the tiles of the board. Either constructs a road or a settlement based on the control buttons the user has clicked.
4659
* @param screenCoord Where the user clicked on screen.

tests/test_TurnAdvancement.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)