Skip to content

Commit 4ab3d62

Browse files
committed
Merge pull request #16 from Databean/dice_operations
Dice operations
2 parents 7fb2f25 + 7b33113 commit 4ab3d62

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

include/GameBoard.h

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

5353
void createRing(Coordinate topRight, int sideLength, std::vector<resourceType>& resources, std::vector<int>& rolls);
5454
void insertTile(Coordinate location, std::vector<resourceType>& resources, std::vector<int>& rolls);
55+
56+
std::pair<int, int> startTurn();
57+
void enableRobber();
58+
void payoutResources(int roll);
59+
5560
public:
5661
GameBoard(std::vector<std::unique_ptr<Player>>&& players);
5762
GameBoard(std::vector<std::unique_ptr<Player>>&& players, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);
1020 KB
Binary file not shown.

src/GameBoard.cpp

Lines changed: 44 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,45 @@ 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+
* @return An array of the dice rolls
606+
*/
607+
std::pair<int, int> GameBoard::startTurn()
608+
{
609+
int die1 = std::rand() % 6 + 1;
610+
int die2 = std::rand() % 6 + 1;
611+
int roll = die1+die2;
612+
std::cout << "\nDie 1: " << die1 << "\nDie 2: " << die2 << "\nRoll: " << roll <<"\n";
613+
614+
if (roll==7)
615+
enableRobber();
616+
617+
else
618+
payoutResources(roll);
619+
620+
return std::make_pair(die1, die2);
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+
for (auto& it : resources)
637+
{
638+
if (it.second->getDiceValue() == roll)
639+
{
640+
it.second->Payout();
641+
}
642+
}
643+
}

0 commit comments

Comments
 (0)