Skip to content

Commit 15c1edf

Browse files
committed
Implemented a start turn function that rolls the dice and either lys out resources or moves the robber. Currently cheats and starts a turn each time a road is placed (for manual testing purposes)
1 parent 159c5a6 commit 15c1edf

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

include/GameBoard.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class GameBoard {
5050

5151
void createRing(Coordinate topRight, int sideLength, std::vector<resourceType>& resources, std::vector<int>& rolls);
5252
void insertTile(Coordinate location, std::vector<resourceType>& resources, std::vector<int>& rolls);
53+
54+
void startTurn();
55+
void enableRobber();
56+
void payoutResources(int roll);
57+
5358
public:
5459
GameBoard(std::vector<std::unique_ptr<Player>>&& players);
5560
GameBoard(std::vector<std::unique_ptr<Player>>&& players, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);

src/GameBoard.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ bool GameBoard::PlaceRoad(Coordinate start, Coordinate end, Player& Owner) {
366366
roads[start].push_back(newRoad);
367367
roads[end].push_back(newRoad);
368368

369+
startTurn();
370+
369371
return true;
370372
}
371373

@@ -597,3 +599,39 @@ bool GameBoard::isValidBoard() const {
597599
const std::vector<std::unique_ptr<Player>>& GameBoard::getPlayers() const {
598600
return players;
599601
}
602+
603+
/*
604+
* When a player begins their turn, this rolls the dice and takes the required action (paying resources or enabling robber movement)
605+
*/
606+
void GameBoard::startTurn()
607+
{
608+
std::srand(std::time(0));
609+
int die1 = std::rand() % 6 + 1;
610+
int die2 = std::rand() % 6 + 1;
611+
int roll = die1+die2;
612+
cout << "Die 1: " << die1 << "\nDie 2: " << die2 << "\nRoll: " << roll;
613+
614+
if (roll==7)
615+
{
616+
enableRobber();
617+
return;
618+
}
619+
620+
payoutResources(roll);
621+
}
622+
623+
/*
624+
* When a 7 is rolled, this enforces resource discarding and allows the current player to move the robber
625+
*/
626+
void GameBoard::enableRobber()
627+
{
628+
//Do some straight up robber stuff.
629+
}
630+
631+
/*
632+
* This pays resources based on the current roll
633+
*/
634+
void GameBoard::payoutResources(int roll)
635+
{
636+
637+
}

0 commit comments

Comments
 (0)