Skip to content

Commit 7dd129b

Browse files
committed
Merge pull request #54 from Databean/KnightImplementation_2
Knight implementation 2
2 parents c6d5586 + 1c827c6 commit 7dd129b

File tree

12 files changed

+339
-121
lines changed

12 files changed

+339
-121
lines changed

include/GameBoard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class GameBoard {
137137

138138
bool testRollChecking(int* rolls);
139139

140-
void moveRobber(Coordinate newRobber);
140+
bool moveRobber(Coordinate newRobber);
141141
Coordinate getRobber() const;
142142
bool canRobberRob(Player& opponent, Coordinate location);
143143

include/GameController.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class GameController {
4747
bool handleMonopolyCardButtonEvent(ScreenCoordinate);
4848
bool handleVictoryPointCardButtonEvent(ScreenCoordinate);
4949

50+
bool handleWoodButtonEvent(ScreenCoordinate);
51+
bool handleSheepButtonEvent(ScreenCoordinate);
52+
bool handleWheatButtonEvent(ScreenCoordinate);
53+
bool handleOreButtonEvent(ScreenCoordinate);
54+
bool handleBrickButtonEvent(ScreenCoordinate);
55+
5056
bool handleCancelButtonEvent(ScreenCoordinate);
5157

5258
bool handleConfirmRoadCard(ScreenCoordinate);

include/GameView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class GameView {
5555
void drawCardCount(std::string font, int fontSize);
5656
void drawResourceCount(std::string font, int fontSize);
5757

58+
std::string controlStateText;
59+
5860
GameView(const GameView& o) = delete;
5961
GameView& operator=(const GameView& o) = delete;
6062
public:
@@ -64,6 +66,8 @@ class GameView {
6466
void render();
6567
bool acceptInput(SDL_Event& event);
6668

69+
void setControlStateText(std::string newText);
70+
6771

6872
void addPointOfInterest(ScreenCoordinate);
6973
void clearPointsOfInterest();

src/GameBoard.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ void GameBoard::createRing(Coordinate topRight, int sideLength, vector<resourceT
100100
void GameBoard::insertTile(Coordinate location, vector<resourceType>& resources, vector<int>& rolls) {
101101
if(rolls.back() == 0) {
102102
addResource(location.first, location.second, DESERT, rolls.back());
103-
//moveRobber(Coordinate(location.first, location.second));
104-
//std::cout << location.first << location.second << "\n";
105103
rolls.pop_back();
106104
} else {
107105
addResource(location.first, location.second, resources.back(), rolls.back());
@@ -406,16 +404,15 @@ std::vector<Settlement*> GameBoard::GetNeighboringSettlements(
406404
* @param location The location to search the neighbors of.
407405
* @return A vector of the corner pieces in the vicinity.
408406
*/
409-
std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(
410-
Coordinate location) const{
411-
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,
412-
0), Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0),
413-
Coordinate(-1, 1) };
407+
std::vector<CornerPiece*> GameBoard::GetNeighboringCorners(Coordinate location) const{
408+
static Coordinate adjacentCoordDiffs[] = { Coordinate(0, 1), Coordinate(1,0),
409+
Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0), Coordinate(-1, 1) };
410+
414411
std::vector<CornerPiece*> v;
415412
for (unsigned int i = 0; i < 6; i++) {
416413
const Coordinate& diff = adjacentCoordDiffs[i];
417-
Coordinate adjacentPoint(location.first + diff.first,
418-
location.second + diff.second);
414+
Coordinate adjacentPoint(location.first + diff.first, location.second + diff.second);
415+
419416
auto it = corners.find(adjacentPoint);
420417
if (it != corners.end()) {
421418
GamePiece* piece = it->second.get();
@@ -523,21 +520,22 @@ bool GameBoard::verifyRoadPlacement(Coordinate start, Coordinate end, Player& Ow
523520
* Move the robber to a new coordinate on the board.
524521
* @param newRobber The coordinate to move the robber to.
525522
*/
526-
void GameBoard::moveRobber(Coordinate newRobber) {
523+
bool GameBoard::moveRobber(Coordinate newRobber) {
527524

528525
//Bounds check
529-
if(resources.count(newRobber) > 0)
526+
if(resources.find(newRobber) != resources.end()){
530527
robber = newRobber;
528+
return true;
529+
}
530+
return false;
531531
}
532532

533533
/**
534-
* DOES NOT WORK BECAUSE getNeighboringCorners() does not work
534+
* Returns whether the robber can rob the Player opponent at the recourse tile Coordinate location
535+
* @return true if the robber can rob the opponent, false otherwise
535536
*/
536537
bool GameBoard::canRobberRob(Player& opponent, Coordinate location){
537-
std::cout << GetNeighboringCorners(location).size() << "\n";
538-
539538
for(auto corner : GetNeighboringCorners(location)){
540-
std::cout << corner->getOwner().getName() << "derp\n";
541539
if(corner->getOwner() == opponent){
542540
return true;
543541
}

0 commit comments

Comments
 (0)