Skip to content

Commit ca9671b

Browse files
committed
Updated tests for Google Test
2 parents 3e0e3ee + 4194963 commit ca9671b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2894
-537
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ warsofcatan
2121
*.wocs
2222

2323
documentation/*
24+
/Debug

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export EXECUTABLE := warsofcatan
77
ALLFILES := $(wildcard $(SRC_HOME)/*) $(wildcard $(INCL_HOME)/*)
88
export CXX := g++
99
export LD := g++
10-
export CXXFLAGS := -g -I$(INCL_HOME) -std=c++0x -Wall
11-
export LDFLAGS := -L/usr/local/lib -lSDL2 -lSDL2_ttf -lGL -lGLU
10+
export CXXFLAGS := -g -I$(INCL_HOME) -std=c++0x -I/usr/include/SDL2 -I/usr/local/include/SDL2 -Wall
11+
export LDFLAGS := -L/usr/local/lib -lSDL2 -lSDL2_ttf -lGL -lGLU -Wl,-R/usr/local/lib
1212

1313
.PHONY: all
1414
all: $(EXECUTABLE)
@@ -24,4 +24,4 @@ tests: $(EXECUTABLE)
2424
.PHONY: clean
2525
clean:
2626
rm -f $(EXECUTABLE)
27-
rm -f obj/*.o
27+
rm -f obj/*.o

include/CornerPiece.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ class CornerPiece : public GamePiece {
1616
CornerPiece(CornerPiece&) = delete;
1717
~CornerPiece();
1818
CornerPiece& operator=(CornerPiece&) = delete;
19-
19+
2020
Player& getOwner();
2121
const Player& getOwner() const;
2222

23+
virtual void accept(GameVisitor& visitor)=0;
24+
2325
virtual int getResourceModifier();
2426

2527
virtual int getVictoryPoints();
28+
29+
virtual bool operator==(const GamePiece&) const;
2630
};
2731

2832
#endif

include/Deck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Deck {
2727
void reshuffleDeck();
2828

2929
public:
30-
Deck(GameBoard& board);
30+
Deck();
3131
virtual ~Deck();
3232

3333
int getSize();

include/DevelopmentCard.h

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
enum DevCardType { KNIGHT, VICTORYPOINT, YEAROFPLENTY, MONOPOLY, ROADBUILDING };
2121

2222

23-
23+
/**
24+
* A card which can be held in a player's hand and be used to perform an action.
25+
*/
2426
class DevelopmentCard {
2527

26-
protected:
28+
private:
2729
DevCardType type;
28-
GameBoard& board;
2930
public:
30-
DevelopmentCard(GameBoard& board);
31+
DevelopmentCard() {}
3132
virtual ~DevelopmentCard();
3233

3334
virtual DevCardType getType() const = 0;
@@ -36,66 +37,53 @@ class DevelopmentCard {
3637
virtual bool operator==(const DevelopmentCard&);
3738
};
3839

39-
40-
40+
/**
41+
* A development card used to move the robber and take a resource from another player.
42+
*/
4143
class KnightCard : public DevelopmentCard {
4244
private:
4345

4446
public:
45-
KnightCard(GameBoard& board);
46-
// virtual ~KnightCard();
47-
47+
KnightCard() {}
4848
virtual DevCardType getType() const;
49-
void playCard(Player *player, Coordinate target);
50-
5149
};
5250

53-
54-
51+
/**
52+
* A development card that gives a permanent victory point on usage.
53+
*/
5554
class VictoryPointCard : public DevelopmentCard {
5655
public:
57-
VictoryPointCard(GameBoard& board);
58-
// virtual ~VictoryPointCard();
59-
56+
VictoryPointCard() {}
6057
virtual DevCardType getType() const;
61-
6258
};
6359

64-
60+
/**
61+
* A development card used to retrieve two resources of any type from the bank.
62+
*/
6563
class YearOfPlentyCard : public DevelopmentCard {
6664
public:
67-
YearOfPlentyCard(GameBoard& board);
68-
// virtual ~YearOfPlentyCard();
69-
65+
YearOfPlentyCard() {}
7066
virtual DevCardType getType() const;
71-
void playCard(Player *player, int rType1, int rType2);
72-
7367
};
7468

75-
76-
77-
69+
/**
70+
* A development card used to take all resources of a particular type from all players.
71+
*/
7872
class MonopolyCard : public DevelopmentCard {
7973
public:
80-
MonopolyCard(GameBoard& board);
81-
// virtual ~MonopolyCard();
82-
74+
MonopolyCard() {}
8375
virtual DevCardType getType() const;
84-
void playCard(Player *player, int rType);
85-
8676
};
8777

88-
89-
78+
/**
79+
* A development card used to build two roads at no cost.
80+
*/
9081
class RoadBuildingCard : public DevelopmentCard {
9182
private:
9283

9384
public:
94-
RoadBuildingCard(GameBoard& board);
95-
// virtual ~RoadBuildingCard();
96-
85+
RoadBuildingCard() {};
9786
virtual DevCardType getType() const;
98-
void playCard(Player* player, Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2);
9987
};
10088

10189

include/GameBoard.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "Settlement.h"
1717
#include "tinyxml2.h"
1818
#include "Road.h"
19-
19+
#include "GameDice.h"
2020

2121
class GameVisitor;
2222

@@ -29,20 +29,25 @@ class GameBoard {
2929

3030
std::map<Coordinate, std::unique_ptr<ResourceTile>> resources;
3131

32+
GameDice dice;
33+
34+
3235

3336
std::map<Coordinate, std::vector<std::shared_ptr<Road>>> roads;
3437

3538
std::vector<std::unique_ptr<Player>> players;
3639
Coordinate robber;
3740

41+
int currentTurn;
42+
43+
int maxVictoryPoints;
3844

3945
void addResource(int x, int y, resourceType res, int val);
4046
bool checkRolls(int* rolls);
4147

4248
bool isValidBoard() const;
4349

4450

45-
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
4651
bool outOfBounds(const Coordinate& coord) const;
4752
bool roadExists(Coordinate start, Coordinate end) const;
4853
bool isRoadConnectionPoint(Coordinate point, Player& Owner) const;
@@ -68,34 +73,44 @@ class GameBoard {
6873
~GameBoard();
6974
GameBoard& operator=(GameBoard&) = delete;
7075

76+
void initializeGame();
77+
7178
void save(std::ostream& out);
7279

7380
ResourceTile& getResourceTile(Coordinate location) const;
7481

7582
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
7683

84+
void endTurn();
85+
Player& getCurrentPlayer() const;
7786

78-
87+
int getMaxVictoryPoints();
88+
void setMaxVictoryPoints(int maxVicPts);
7989
const std::shared_ptr<Road> getRoad(Coordinate start, Coordinate end) const;
8090
const std::vector<std::shared_ptr<Road>>& getRoads(Coordinate loc) const;
8191

8292
int FindLongestRoad(const Player & owner) const;
93+
void updateLongestRoadPlayer();
94+
void updateLargestArmyPlayer();
8395

8496
std::vector<Settlement*> GetNeighboringSettlements(Coordinate location) const;
8597
std::vector<CornerPiece*> GetNeighboringCorners(Coordinate location) const;
8698

87-
99+
int CountCornerPoints(Player& owner);
88100

89101
void PlaceSettlement(Coordinate location, Player& Owner);
90102
void UpgradeSettlement(Coordinate location);
91-
//void PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
103+
void UpgradeToWonder(Coordinate location);
92104

93105

106+
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
94107
bool buyRoad(Coordinate start, Coordinate end, Player& Owner);
95108

96109
//void PlaceSettlement(Coordinate location, Player& Owner);
97110
void PlaceCity(Coordinate location, Player& Owner);
111+
void PlaceWonder(Coordinate location, Player& Owner);
98112
bool PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
113+
bool canPlayBuildRoadCard(Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2, Player& Owner);
99114

100115
void accept(GameVisitor& visitor);
101116

@@ -110,6 +125,7 @@ class GameBoard {
110125

111126
void moveRobber(Coordinate newRobber);
112127
Coordinate getRobber() const;
128+
bool canRobberRob(Player& opponent, Coordinate location);
113129

114130
};
115131

include/GameController.h

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,64 @@
22
#define GAME_CONTROLLER_H
33

44
#include "Util.h"
5+
#include <vector>
6+
7+
#include <array>
58

69
class GameBoard;
710
class ClickCoordinateEvent;
811
class GameView;
12+
class Player;
13+
14+
15+
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, ROBBER,
16+
VICTORYPOINT_DEVCARD, BUILDROAD_DEVCARD, KNIGHT_DEVCARD, YEAROFPLENTY_DEVCARD, MONOPOLY_DEVCARD};
17+
918

1019
/**
11-
* Takes interpreted Catan events from the View and calls the appropriate functions on the model to changee the state
20+
* Takes interpreted Catan events from the View and calls the appropriate functions on the model to change the state
1221
* in response.
1322
*/
1423
class GameController {
1524
private:
1625
GameBoard& model;
1726
GameView& view;
1827

19-
bool placingRoads;
20-
bool placingCities;
21-
Coordinate lastCoordClick;
28+
std::vector<ControlState> stateStack;
29+
std::vector<Coordinate> clickHistory;
2230

2331
GameController(const GameController& o) : model(o.model), view(o.view) {} //deleted
2432
GameController& operator=(const GameController& o) { return *this; } //deleted
2533
public:
2634
GameController(GameBoard&, GameView& view);
2735
~GameController();
2836

37+
bool nextTurn(ScreenCoordinate);
2938
bool handleBoardEvent(ScreenCoordinate);
3039
bool handleRoadButtonEvent(ScreenCoordinate);
3140
bool handleSettlementButtonEvent(ScreenCoordinate);
41+
bool handleRoadCardButtonEvent(ScreenCoordinate);
42+
bool handleKnightCardButtonEvent(ScreenCoordinate);
43+
bool handleYearOfPlentyCardButtonEvent(ScreenCoordinate);
44+
bool handleMonopolyCardButtonEvent(ScreenCoordinate);
45+
bool handleVictoryPointCardButtonEvent(ScreenCoordinate);
46+
bool handleCancelButtonEvent(ScreenCoordinate);
47+
48+
bool handleConfirmRoadCard(ScreenCoordinate);
49+
bool handleCancelDialogueEvent(ScreenCoordinate);
50+
51+
void pushState(ControlState);
52+
ControlState getState();
53+
ControlState popState();
54+
void storeClick(Coordinate clickCoordinate);
55+
Coordinate getLastClick();
56+
Coordinate getPastClick(int howLongAgo);
57+
void clearClickHistory();
58+
bool hasClickHistory();
59+
int getClickHistorySize();
60+
61+
bool handlePlayerClick(ScreenCoordinate, Player&);
62+
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
3263
};
3364

34-
#endif
65+
#endif

include/GameDice.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef GAMEDICE_H
2+
#define GAMEDICE_H
3+
4+
class GameVisitor;
5+
6+
/**
7+
* The two dice used to determine the tiles that give resources.
8+
*/
9+
class GameDice {
10+
private:
11+
int first;
12+
int second;
13+
public:
14+
int roll();
15+
int getFirst() const;
16+
int getSecond() const;
17+
virtual void accept(GameVisitor& visitor);
18+
};
19+
20+
#endif

0 commit comments

Comments
 (0)