Skip to content

Commit 94c0c8b

Browse files
committed
Merge pull request #49 from Databean/robber_finishing
Robber finishing
2 parents 0c57beb + fa2f10c commit 94c0c8b

File tree

7 files changed

+88
-3
lines changed

7 files changed

+88
-3
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
@@ -62,6 +62,8 @@ class GameController {
6262
bool hasClickHistory();
6363
int getClickHistorySize();
6464

65+
void robPlayers();
66+
6567
bool handlePlayerClick(ScreenCoordinate, Player&);
6668
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
6769
};

resources/catan_sprite_sheet.bmp

0 Bytes
Binary file not shown.

src/GameBoard.cpp

Lines changed: 7 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
/**
@@ -98,6 +100,8 @@ void GameBoard::createRing(Coordinate topRight, int sideLength, vector<resourceT
98100
void GameBoard::insertTile(Coordinate location, vector<resourceType>& resources, vector<int>& rolls) {
99101
if(rolls.back() == 0) {
100102
addResource(location.first, location.second, DESERT, rolls.back());
103+
//moveRobber(Coordinate(location.first, location.second));
104+
//std::cout << location.first << location.second << "\n";
101105
rolls.pop_back();
102106
} else {
103107
addResource(location.first, location.second, resources.back(), rolls.back());
@@ -126,6 +130,9 @@ GameBoard::GameBoard(const std::vector<std::string>& playerNames, const std::map
126130
currentTurn = 0;
127131
}
128132

133+
GameDice GameBoard::getDice() {
134+
return dice;
135+
}
129136
/**
130137
* Construct a board by reading in an XML representation from a stream.
131138
* @param in The stream to read from.

src/GameController.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ void printPlayerInfo(const Player& player) {
144144
*/
145145
bool GameController::nextTurn(ScreenCoordinate) {
146146
model.endTurn();
147+
if (model.getDice().getFirst() + model.getDice().getSecond() == 7)
148+
pushState(ROBBER);
149+
147150
printPlayerInfo(model.getCurrentPlayer());
148151
return true;
149152
}
@@ -157,6 +160,8 @@ bool GameController::nextTurn(ScreenCoordinate) {
157160
bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
158161
printPlayerInfo(model.getCurrentPlayer());
159162
auto coord = screenToCoord(screenCoord);
163+
std::vector<Settlement*> neighbors;
164+
int resourceToSteal;
160165

161166
switch (getState()){
162167
case BUILDROAD:
@@ -172,6 +177,19 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
172177
break;
173178
case ROBBER:
174179
//model.moveRobber(coord);
180+
robPlayers();
181+
182+
if(!hasClickHistory())
183+
storeClick(coord);
184+
185+
model.moveRobber(coord);
186+
neighbors = model.GetNeighboringSettlements(coord);
187+
if (!neighbors.empty()) {
188+
resourceToSteal = neighbors[0]->getOwner().getRandomResource();
189+
neighbors[0]->getOwner().addResource(resourceToSteal, -1);
190+
model.getCurrentPlayer().addResource(resourceToSteal, 1);
191+
}
192+
175193
popState();
176194
break;
177195
case BUILDROAD_DEVCARD:
@@ -187,6 +205,21 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
187205
break;
188206
case KNIGHT_DEVCARD:
189207
//model.getCurrentPlayer().playKnight(coord, opponent);
208+
if(!hasClickHistory())
209+
storeClick(coord);
210+
211+
model.moveRobber(coord);
212+
neighbors = model.GetNeighboringSettlements(coord);
213+
if (!neighbors.empty()) {
214+
resourceToSteal = neighbors[0]->getOwner().getRandomResource();
215+
neighbors[0]->getOwner().addResource(resourceToSteal, -1);
216+
model.getCurrentPlayer().addResource(resourceToSteal, 1);
217+
}
218+
219+
//TODO Decrement knight count
220+
221+
222+
190223
popState();
191224
break;
192225
case YEAROFPLENTY_DEVCARD:
@@ -217,6 +250,26 @@ bool GameController::handleBoardEvent(ScreenCoordinate screenCoord) {
217250
return true;
218251
}
219252

253+
void GameController :: robPlayers() {
254+
for (int i = 0; i < model.getNoOfPlayers(); i++) {
255+
int resources[5];
256+
model.getPlayer(i).checkResources(resources);
257+
//int rSum = resources[0] + resources[1] + resources[2] + resources[3] + resources[4];
258+
int rSum = model.getPlayer(i).getWood() +
259+
model.getPlayer(i).getOre() +
260+
model.getPlayer(i).getBrick() +
261+
model.getPlayer(i).getWheat() +
262+
model.getPlayer(i).getWool();
263+
264+
if (rSum > 7) {
265+
for (int j = 0 ; j < rSum/2; j++) {
266+
model.getPlayer(i).addResource(model.getPlayer(i).getRandomResource(), -1);
267+
268+
}
269+
}
270+
}
271+
}
272+
220273
/**
221274
* Handles the event when the cancel button in the top right corner of the screen is pressed. This will
222275
* 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

src/GameView.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ void drawTexturedRectangle(std::pair<float, float> texTopLeft, float sideLength,
562562
void DrawingGameVisitor::visit(GameDice& dice) {
563563

564564
static const GLuint diceTextures = loadImageAsTexture("resources/catan_dice_new.bmp");
565+
static const GLuint gameTextures = loadImageAsTexture("resources/catan_sprite_sheet_thatnewnew.bmp");
565566
glBindTexture(GL_TEXTURE_2D, diceTextures);
566567

567568
glColor3d(1.0, 1.0, 1.0);
@@ -583,6 +584,8 @@ void DrawingGameVisitor::visit(GameDice& dice) {
583584

584585

585586
glBindTexture(GL_TEXTURE_2D, 0);
587+
588+
586589

587590
}
588591

@@ -645,7 +648,15 @@ void DrawingGameVisitor::visit(ResourceTile& tile) {
645648
glEnd();
646649

647650
if(tile.getDiceValue() != 0) {
648-
drawTexturedCircle(numberTexPoints.find(tile.getDiceValue())->second, radius, coordToScreen(coord), 0.04);
651+
if (tile.getBoard().getRobber() == coord) { //draw the robber on this tile
652+
//static const GLuint robberTextures = loadImageAsTexture("resource/catan_sprite_sheet_thatnewnew.bmp");
653+
654+
//glBindTexture(GL_TEXTURE_2D, robberTextures);
655+
//glColor3d(1.0, 1.0, 1.0);
656+
drawTexturedCircle(make_pair(1240.f, 643.f), 59.5f, coordToScreen(coord), 0.04);
657+
}
658+
else
659+
drawTexturedCircle(numberTexPoints.find(tile.getDiceValue())->second, radius, coordToScreen(coord), 0.04);
649660
}
650661
glBindTexture(GL_TEXTURE_2D, 0);
651662

0 commit comments

Comments
 (0)