Skip to content

Commit 94cd999

Browse files
committed
Merge branch 'master' into moreSoftConfig
2 parents bd7aea8 + fe5d202 commit 94cd999

File tree

13 files changed

+468
-59
lines changed

13 files changed

+468
-59
lines changed

include/GameBoard.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class GameBoard {
4343
Coordinate robber;
4444

4545
int currentTurn;
46-
4746
int maxVictoryPoints;
47+
int winner;
4848

4949
void addResource(int x, int y, resourceType res, int val);
5050
bool checkRolls(int* rolls);
@@ -92,6 +92,8 @@ class GameBoard {
9292

9393
void endTurn();
9494
Player& getCurrentPlayer() const;
95+
bool hasWinner();
96+
Player& getWinner() const;
9597

9698
int getMaxVictoryPoints();
9799
void setMaxVictoryPoints(int maxVicPts);
@@ -120,6 +122,9 @@ class GameBoard {
120122
bool canUpgradeSettlement(Coordinate location, const Player& owner) const;
121123
bool buyUpgradeOnSettlement(Coordinate location, Player& owner);
122124

125+
bool canUpgradeToWonder(Coordinate location, const Player& owner) const;
126+
bool buyUpgradeOnWonder(Coordinate location, Player& owner);
127+
123128
//void PlaceSettlement(Coordinate location, Player& Owner);
124129
void PlaceCity(Coordinate location, Player& Owner);
125130
void PlaceWonder(Coordinate location, Player& Owner);

include/GameController.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GameView;
1212
class Player;
1313

1414

15-
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, BUILDCITY, ROBBER,
15+
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, BUILDCITY, BUILDWONDER, ROBBER,
1616
VICTORYPOINT_DEVCARD, BUILDROAD_DEVCARD, KNIGHT_DEVCARD, YEAROFPLENTY_DEVCARD, MONOPOLY_DEVCARD};
1717

1818

@@ -39,6 +39,7 @@ class GameController {
3939
bool handleRoadButtonEvent(ScreenCoordinate);
4040
bool handleSettlementButtonEvent(ScreenCoordinate);
4141
bool handleCityButtonEvent(ScreenCoordinate);
42+
bool handleWonderButtonEvent(ScreenCoordinate);
4243
bool handleRoadCardButtonEvent(ScreenCoordinate);
4344

4445
bool handleBuyDevelopmentCardButtonEvent(ScreenCoordinate);
@@ -57,13 +58,15 @@ class GameController {
5758

5859
bool handleConfirmRoadCard(ScreenCoordinate);
5960
bool handleCancelDialogueEvent(ScreenCoordinate);
61+
62+
bool viewCardTotals(ScreenCoordinate coord);
6063

6164
void pushState(ControlState);
6265
ControlState getState();
6366
ControlState popState();
6467
void storeClick(Coordinate clickCoordinate);
6568
Coordinate getLastClick();
66-
Coordinate getPastClick(int howLongAgo);
69+
Coordinate getPastClick(unsigned int howLongAgo);
6770
void clearClickHistory();
6871
bool hasClickHistory();
6972
int getClickHistorySize();
@@ -72,6 +75,8 @@ class GameController {
7275

7376
bool handlePlayerClick(ScreenCoordinate, Player&);
7477
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
78+
79+
bool handleBankClick(ScreenCoordinate);
7580
};
7681

7782
#endif

include/GameDice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class GameDice {
1111
int first;
1212
int second;
1313
public:
14+
GameDice();
15+
1416
int roll();
1517
int getFirst() const;
1618
int getSecond() const;

include/GameView.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ class GameView {
5252
std::vector<ScreenCoordinate> pointsOfInterest;
5353

5454
void highlightPoint(ScreenCoordinate & coord);
55-
void drawCardCount(std::string font, int fontSize);
56-
void drawResourceCount(std::string font, int fontSize);
5755

5856
std::string controlStateText;
5957

6058
GameView(const GameView& o) = delete;
6159
GameView& operator=(const GameView& o) = delete;
60+
6261
public:
6362
GameView(GameBoard&);
6463
~GameView();
@@ -78,6 +77,10 @@ class GameView {
7877
std::unique_ptr<ViewElement> removeElement(int priority);
7978
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
8079
std::unique_ptr<ViewElement> removeElement(const ViewElement&);
80+
81+
void drawCardCount(std::string font, int fontSize);
82+
void drawResourceCount(std::string font, int fontSize);
83+
bool showTotals;
8184
};
8285

8386
/**
@@ -202,8 +205,8 @@ std::unique_ptr<ViewElement> makeViewButtonText(Fn fn, std::pair<ScreenCoordinat
202205

203206
class TradingView : public ViewElement {
204207
private:
205-
Player& initiating;
206-
Player& receiving;
208+
std::string initiating;
209+
std::string receiving;
207210

208211
ViewButtonText trade;
209212
ViewButtonText cancel;
@@ -215,7 +218,7 @@ class TradingView : public ViewElement {
215218
protected:
216219
virtual bool clicked(ScreenCoordinate coord);
217220
public:
218-
TradingView(Player& initiating, Player& receiving, std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade, std::function<bool(ScreenCoordinate)> cancel, std::array<int, 5> offer);
221+
TradingView(const std::string& initiating, const std::string& receiving, std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade, std::function<bool(ScreenCoordinate)> cancel, std::array<int, 5> offer);
219222
virtual ~TradingView();
220223

221224
void render();

include/Player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Player {
116116

117117
void setGenralModifier(); //3:1 port
118118

119-
bool offerBankTrade(std::array<int, 5> offer, std::array<int, 5> demand);
119+
bool makeBankTrade(std::array<int, 5> offer, std::array<int, 5> demand);
120120

121121
bool acceptOffer(Player& p, std::array<int, 5> offer, std::array<int, 5> demand);
122122

src/GameBoard.cpp

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
4040
}
4141

4242
currentTurn = 0;
43+
maxVictoryPoints = 10;
44+
winner = -1;
4345

4446
std::srand(std::time(0));
4547

@@ -74,7 +76,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
7476
}
7577
std::cout << getRobber().first << "\n";
7678
std::cout << getRobber().second << "\n";
77-
79+
80+
maxVictoryPoints = 10;
7881
}
7982

8083
/**
@@ -134,6 +137,8 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
134137
throw std::runtime_error("Board is invalid.");
135138
}
136139
currentTurn = 0;
140+
maxVictoryPoints = 10;
141+
winner = -1;
137142
}
138143

139144
GameDice GameBoard::getDice() {
@@ -267,7 +272,9 @@ GameBoard::GameBoard(istream& in) {
267272
throw std::runtime_error("Board is invalid.");
268273
}
269274

270-
currentTurn = 0; //have to update <<--
275+
currentTurn = 0; //have to update
276+
maxVictoryPoints = 0;
277+
winner = -1;
271278
}
272279

273280
/**
@@ -328,8 +335,12 @@ ResourceTile& GameBoard::getResourceTile(Coordinate location) const
328335
*/
329336
void GameBoard::endTurn()
330337
{
338+
std::cout << currentTurn << std::endl;
331339
if(getCurrentPlayer().getVictoryPoints() >= getMaxVictoryPoints())
332-
std::cout<<"GG Bitches";
340+
{
341+
//std::cout<<"GG Bitches";
342+
winner = currentTurn;
343+
}
333344

334345
currentTurn++;
335346
if(currentTurn >= getNoOfPlayers())
@@ -873,6 +884,43 @@ bool GameBoard::buyUpgradeOnSettlement(Coordinate location, Player& owner) {
873884
return false;
874885
}
875886

887+
/**
888+
* Whether a settlement/city at a location can be upgraded to a wonder.
889+
*/
890+
bool GameBoard::canUpgradeToWonder(Coordinate location, const Player& owner) const {
891+
auto it = corners.find(location);
892+
if(it == corners.end()) {
893+
std::cout << "there's nothing there" << std::endl;
894+
return false;
895+
}
896+
if(!it->second) {
897+
std::cout << "null ptr there" << std::endl;
898+
return false;
899+
}
900+
if(!(it->second->getOwner() == owner)) {
901+
std::cout << "wrong owner" << std::endl;
902+
return false;
903+
}
904+
if(dynamic_cast<const Settlement*>(it->second.get()) == 0 && dynamic_cast<const City*>(it->second.get()) == 0) {
905+
std::cout << "this isn't a settlement or city" << std::endl;
906+
return false;
907+
}
908+
return true;
909+
}
910+
911+
bool GameBoard::buyUpgradeOnWonder(Coordinate location, Player& owner) {
912+
if(canUpgradeToWonder(location, owner) && owner.canBuyCity()) {
913+
if(!owner.buyWonder()) {
914+
std::cout << "wat" << std::endl;
915+
return false;
916+
}
917+
UpgradeToWonder(location);
918+
return true;
919+
}
920+
std::cout << "failed for some reason" << std::endl;
921+
return false;
922+
}
923+
876924
/**
877925
* Place a city on the board.
878926
* @param location Where to place it on the board.
@@ -1056,6 +1104,31 @@ Player& GameBoard::getCurrentPlayer() const
10561104
return *players[currentTurn];
10571105
}
10581106

1107+
1108+
1109+
/**
1110+
* @return true if game has a winner, false otherwise
1111+
*/
1112+
bool GameBoard::hasWinner()
1113+
{
1114+
if(winner == -1)
1115+
return false;
1116+
return true;
1117+
}
1118+
1119+
1120+
/**
1121+
* @return reference to the winner if there is one, null otherwise
1122+
*/
1123+
Player& GameBoard::getWinner() const
1124+
{
1125+
if(winner != -1 && winner < players.size())
1126+
return *players[winner];
1127+
1128+
return *players[0];
1129+
}
1130+
1131+
10591132
/**
10601133
* @return no of players
10611134
*/

0 commit comments

Comments
 (0)