Skip to content

Commit 4036386

Browse files
committed
Merge branch 'master' into KnightImplementation_2
Conflicts: src/GameController.cpp
2 parents 1ed2ac1 + 94c0c8b commit 4036386

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

include/GameBoard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class GameBoard {
7979

8080
void initializeGame();
8181

82+
GameDice getDice();
83+
8284
void save(std::ostream& out);
8385

8486
void buyCard(Player& owner);

include/GameController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class GameController {
6868
bool hasClickHistory();
6969
int getClickHistorySize();
7070

71+
void robPlayers();
72+
7173
bool handlePlayerClick(ScreenCoordinate, Player&);
7274
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
7375
};

resources/catan_sprite_sheet.bmp

0 Bytes
Binary file not shown.

src/GameBoard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ GameBoard::GameBoard(const vector<std::string>& playerNames) {
6565
}
6666
valid = isValidBoard();
6767
}
68+
moveRobber(Coordinate(0,4));
69+
6870
}
6971

7072
/**
@@ -126,6 +128,9 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
126128
currentTurn = 0;
127129
}
128130

131+
GameDice GameBoard::getDice() {
132+
return dice;
133+
}
129134
/**
130135
* Construct a board by reading in an XML representation from a stream.
131136
* @param in The stream to read from.

src/GameController.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ void printPlayerInfo(const Player& player) {
149149
*/
150150
bool GameController::nextTurn(ScreenCoordinate) {
151151
model.endTurn();
152+
if (model.getDice().getFirst() + model.getDice().getSecond() == 7)
153+
pushState(ROBBER);
154+
152155
printPlayerInfo(model.getCurrentPlayer());
153156
return true;
154157
}
@@ -163,6 +166,8 @@ bool GameController::nextTurn(ScreenCoordinate) {
163166
bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
164167
printPlayerInfo(model.getCurrentPlayer());
165168
auto coord = screenToCoord(screenCoord);
169+
std::vector<Settlement*> neighbors;
170+
int resourceToSteal;
166171

167172
switch (getState()){
168173
case BUILDROAD:
@@ -178,6 +183,19 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
178183
break;
179184
case ROBBER:
180185
//model.moveRobber(coord);
186+
robPlayers();
187+
188+
if(!hasClickHistory())
189+
storeClick(coord);
190+
191+
model.moveRobber(coord);
192+
neighbors = model.GetNeighboringSettlements(coord);
193+
if (!neighbors.empty()) {
194+
resourceToSteal = neighbors[0]->getOwner().getRandomResource();
195+
neighbors[0]->getOwner().addResource(resourceToSteal, -1);
196+
model.getCurrentPlayer().addResource(resourceToSteal, 1);
197+
}
198+
181199
popState();
182200
break;
183201
case BUILDROAD_DEVCARD:
@@ -194,6 +212,26 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
194212
case KNIGHT_DEVCARD:
195213
storeClick(coord);
196214
view.setControlStateText("Select a player around that tile to steal from (Select yourself if you don't want to rob anyone)");
215+
//model.getCurrentPlayer().playKnight(coord, opponent);
216+
/**if(!hasClickHistory())
217+
storeClick(coord);
218+
219+
model.moveRobber(coord);
220+
neighbors = model.GetNeighboringSettlements(coord);
221+
if (!neighbors.empty()) {
222+
resourceToSteal = neighbors[0]->getOwner().getRandomResource();
223+
neighbors[0]->getOwner().addResource(resourceToSteal, -1);
224+
model.getCurrentPlayer().addResource(resourceToSteal, 1);
225+
}
226+
227+
//TODO Decrement knight count
228+
229+
230+
231+
popState();**/
232+
break;
233+
case YEAROFPLENTY_DEVCARD:
234+
model.getCurrentPlayer().playYearOfPlenty(model.getResourceTile(coord).getType());
197235
popState();
198236
break;
199237
case VICTORYPOINT_DEVCARD:
@@ -216,6 +254,26 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
216254
return true;
217255
}
218256

257+
void GameController :: robPlayers() {
258+
for (int i = 0; i < model.getNoOfPlayers(); i++) {
259+
int resources[5];
260+
model.getPlayer(i).checkResources(resources);
261+
//int rSum = resources[0] + resources[1] + resources[2] + resources[3] + resources[4];
262+
int rSum = model.getPlayer(i).getWood() +
263+
model.getPlayer(i).getOre() +
264+
model.getPlayer(i).getBrick() +
265+
model.getPlayer(i).getWheat() +
266+
model.getPlayer(i).getWool();
267+
268+
if (rSum > 7) {
269+
for (int j = 0 ; j < rSum/2; j++) {
270+
model.getPlayer(i).addResource(model.getPlayer(i).getRandomResource(), -1);
271+
272+
}
273+
}
274+
}
275+
}
276+
219277
/**
220278
* Handles the event when the cancel button in the top right corner of the screen is pressed. This will
221279
* reset the control state back to the base state.

src/GamePiece.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,22 @@ void ResourceTile::Payout() const{
116116
if (getBoard().getRobber() == location) //no need to pay out
117117
return;
118118

119-
std::vector<CornerPiece*> neighbors = getBoard().GetNeighboringCorners(location);
120-
std::vector<CornerPiece*>::iterator it = neighbors.begin();
119+
//std::vector<CornerPiece*> neighbors = getBoard().GetNeighboringCorners(location);
120+
//std::vector<CornerPiece*>::iterator it = neighbors.begin();
121+
122+
std::vector<Settlement*> neighbors = getBoard().GetNeighboringSettlements(location);
123+
std::vector<Settlement*>::iterator it = neighbors.begin();
121124
while (it != neighbors.end())
122125
{
123126
(*it)->getOwner().addResource(resource, (*it)->getResourceModifier());
127+
/*std::cout << ((*it)->getOwner().getWood()) << "\n";
128+
std::cout << ((*it)->getOwner().getBrick()) << "\n";
129+
std::cout << ((*it)->getOwner().getOre()) << "\n";
130+
std::cout << ((*it)->getOwner().getWheat()) << "\n";
131+
std::cout << ((*it)->getOwner().getWool()) << "\n";*/
132+
124133
it++;
125134
}
135+
126136
}
127137

0 commit comments

Comments
 (0)