Skip to content

Commit 25e186b

Browse files
author
ankit21
committed
"end turn button"
1 parent 826f9ef commit 25e186b

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

include/GameBoard.h

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

38+
int currentTurn;
39+
40+
int maxVictoryPoints;
3841

3942
void addResource(int x, int y, resourceType res, int val);
4043
bool checkRolls(int* rolls);
@@ -74,7 +77,11 @@ class GameBoard {
7477

7578
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
7679

80+
void endTurn();
81+
Player& getCurrentPlayer() const;
7782

83+
int getMaxVictoryPoints();
84+
void setMaxVictoryPoints(int maxVicPts);
7885

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

include/GameController.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class GameController {
2626
GameController(GameBoard&, GameView& view);
2727
~GameController();
2828

29+
void nextTurn(ScreenCoordinate);
30+
2931
bool handleBoardEvent(ScreenCoordinate);
3032
bool handleRoadButtonEvent(ScreenCoordinate);
3133
bool handleSettlementButtonEvent(ScreenCoordinate);
3234
};
3335

34-
#endif
36+
#endif

src/GameBoard.cpp

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

40+
currentTurn = 0;
41+
4042
std::srand(std::time(0));
4143

4244
const static vector<resourceType> boardResources {BRICK, BRICK, BRICK, STONE, STONE, STONE, WHEAT, WHEAT, WHEAT, WHEAT, WOOD, WOOD, WOOD, WOOD, SHEEP, SHEEP, SHEEP, SHEEP};
@@ -119,6 +121,7 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
119121
if(!isValidBoard()) {
120122
throw std::runtime_error("Board is invalid.");
121123
}
124+
currentTurn = 0;
122125
}
123126

124127
/**
@@ -227,6 +230,8 @@ GameBoard::GameBoard(istream& in) {
227230
if(!isValidBoard()) {
228231
throw std::runtime_error("Board is invalid.");
229232
}
233+
234+
currentTurn = 0; //have to update <<--
230235
}
231236

232237
/**
@@ -281,6 +286,50 @@ ResourceTile& GameBoard::getResourceTile(Coordinate location) const
281286
return *(resources.find(location)->second);
282287
}
283288

289+
290+
/**
291+
* Ends current players turn and moves the current turn marker
292+
*/
293+
void GameBoard::endTurn()
294+
{
295+
if(getCurrentPlayer().getVictoryPoints() >= getMaxVictoryPoints())
296+
std::cout<<"GG Bitches";
297+
298+
currentTurn++;
299+
if(currentTurn >= getNoOfPlayers())
300+
currentTurn = 0;
301+
302+
startTurn();
303+
}
304+
305+
/**
306+
* @return reference to the current Player
307+
*/
308+
Player& GameBoard::getCurrentPlayer() const
309+
{
310+
return *players[currentTurn];
311+
}
312+
313+
314+
/**
315+
* @return The no of Victory points needed to win the game
316+
*/
317+
int GameBoard::getMaxVictoryPoints()
318+
{
319+
return maxVictoryPoints;
320+
}
321+
322+
323+
/**
324+
* Sets the no of victory points needed to win the game
325+
* @param maxVicPts victory points needed to win the game
326+
*/
327+
void GameBoard::setMaxVictoryPoints(int maxVicPts)
328+
{
329+
maxVictoryPoints = maxVicPts;
330+
}
331+
332+
284333
/**
285334
* Finds settlements neighboring a particular coordinate.
286335
* @param location The location to search the neighbors of.
@@ -455,7 +504,7 @@ bool GameBoard::PlaceRoad(Coordinate start, Coordinate end, Player& Owner) {
455504
roads[start].push_back(newRoad);
456505
roads[end].push_back(newRoad);
457506

458-
startTurn();
507+
// startTurn();
459508

460509
return true;
461510
}

src/GameController.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
GameController::GameController(GameBoard& model, GameView& view) : model(model), view(view), placingRoads(false), placingCities(false) ,lastCoordClick(-100, -100) {
1616
using namespace std::placeholders;
1717

18+
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)));
1819
view.addElement(makeViewButtonColor(std::bind(&GameController::handleRoadButtonEvent, this, _1), {{0, 0}, {0.1, 0.1}}, std::make_tuple(1.f, 0.f, 0.f)));
1920
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)));
2021
view.addElement(makeViewButton(std::bind(&GameController::handleBoardEvent, this, _1), {{0, 0}, {1, 1}}));
@@ -27,6 +28,14 @@ GameController::~GameController() {
2728

2829
}
2930

31+
/**
32+
* calls a function to advance turn, check for victory and roll dice
33+
*/
34+
void GameController::nextTurn(ScreenCoordinate) {
35+
model.endTurn();
36+
}
37+
38+
3039
/**
3140
* 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.
3241
* @param screenCoord Where the user clicked on screen.

0 commit comments

Comments
 (0)