Skip to content

Commit adcb0ec

Browse files
author
ankit21
committed
Merge branch 'master' into refactor_deck
Conflicts: src/GameBoard.cpp
2 parents 883d734 + 2683c37 commit adcb0ec

24 files changed

+1715
-1325
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>warsofcatan</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>

README.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
____ __ ____ ___ .______ _______. ______ _______ ______ ___ .___________. ___ .__ __.
2+
\ \ / \ / / / \ | _ \ / | / __ \ | ____| / | / \ | | / \ | \ | |
3+
\ \/ \/ / / ^ \ | |_) | | (----` | | | | | |__ | ,----' / ^ \ `---| |----` / ^ \ | \| |
4+
\ / / /_\ \ | / \ \ | | | | | __| | | / /_\ \ | | / /_\ \ | . ` |
5+
\ /\ / / _____ \ | |\ \----.----) | | `--' | | | | `----./ _____ \ | | / _____ \ | |\ |
6+
\__/ \__/ /__/ \__\ | _| `._____|_______/ \______/ |__| \______/__/ \__\ |__| /__/ \__\ |__| \__|
7+
8+
9+
Contributors: Ankit Bhutani, Paul Graff, Kyle Grage, Marty Malecki, Alex Politakis, Cody Schuffelen
10+
11+
12+
13+
14+
15+
Congratulations on your purchase of Wars of Catan!
16+
This program recreates the popular board game, Settlers of Catan, with a few added features.
17+
18+
To begin, ensure you have 4 players. The player whose birthday is closes to the current day is player 1, and will command the Southern Tribes.
19+
Players are subsequently assigned clockwise from player 1. This assignment must happen before launching! Run the enclosed executable warsofcatan.exe.
20+
21+
Players control the following empires:
22+
23+
Player 1: Southern Tribes
24+
Player 2: Western Watch
25+
Player 3: North Guard
26+
Player 4: East Raiders
27+
28+
Each player begins the game with one road building card, to be used however the player sees fit.
29+
30+
For rules on playing the game, see catan.com/service/game-rules
31+
32+
To purchase any of the structures available in the game, click on the corresponding button at the bottom left.
33+
To purchase a development card, click on the Development card text at the bottom right.
34+
35+
Note: Purchasing a wonder requires 5 of every resource, and grants an instant 10 victory points.
36+
37+
FAQ:
38+
Q: Why can't I see how many resources I have?
39+
A: To discourage cheating, resource totals are obscured upon changing turns. A player can see his/her totals by clicking the "Display Totals" button.
40+
41+
Q: How can I contribute to the project?
42+
A: The project is open source, and hosted at http:github.com/Databean/warsofcatan. Contributors should reference warsofcatan/src/BoardLayout.txt/
43+
44+
Q: How did you come up with the idea for the wonder? I've literally never had so much fun with a gameplay element.
45+
46+
47+
48+
49+
50+
51+
52+
53+

include/GameBoard.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "GameDice.h"
2020
#include "Deck.h"
2121

22-
#include "DevelopmentCard.h"
22+
//#include "DevelopmentCard.h"
2323

2424

2525
class GameVisitor;
@@ -64,11 +64,11 @@ class GameBoard {
6464

6565
void createRing(Coordinate topRight, int sideLength, std::vector<resourceType>& resources, std::vector<int>& rolls);
6666
void insertTile(Coordinate location, std::vector<resourceType>& resources, std::vector<int>& rolls);
67-
67+
6868
std::pair<int, int> startTurn();
6969
void enableRobber();
7070
void payoutResources(int roll);
71-
71+
7272
public:
7373
GameBoard(const std::vector<std::string>& playerNames);
7474
GameBoard(const std::vector<std::string>& playerNames, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);
@@ -112,16 +112,16 @@ class GameBoard {
112112
void PlaceSettlement(Coordinate location, Player& Owner);
113113
void UpgradeSettlement(Coordinate location);
114114
void UpgradeToWonder(Coordinate location);
115-
115+
116116
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
117117
bool buyRoad(Coordinate start, Coordinate end, Player& Owner);
118-
118+
119119
bool canPlaceSettlement(const Coordinate& location, const Player& owner);
120120
bool buySettlement(const Coordinate& location, Player& owner);
121-
121+
122122
bool canUpgradeSettlement(Coordinate location, const Player& owner) const;
123123
bool buyUpgradeOnSettlement(Coordinate location, Player& owner);
124-
124+
125125
bool canUpgradeToWonder(Coordinate location, const Player& owner) const;
126126
bool buyUpgradeOnWonder(Coordinate location, Player& owner);
127127

@@ -136,7 +136,7 @@ class GameBoard {
136136
bool operator==(const GameBoard& other) const;
137137

138138
const std::vector<std::unique_ptr<Player>>& getPlayers() const;
139-
139+
140140
int getNoOfPlayers();
141141
Player& getPlayer(int index);
142142

include/GameView.h

Lines changed: 11 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -18,84 +18,59 @@ class GameController;
1818
class ViewElement;
1919
class GameView;
2020

21-
22-
/**
23-
* An element that is drawn on screen and can receive inputs from the user. These all occupy a rectangular area on screen
24-
* and can choose to handle clicks from the user that are inside their area.
25-
*/
26-
class ViewElement {
27-
private:
28-
std::pair<ScreenCoordinate, ScreenCoordinate> rect;
29-
30-
ViewElement(const ViewElement& vw) {} //deleted
31-
ViewElement& operator=(const ViewElement&) { return *this; } // deleted
32-
protected:
33-
virtual bool clicked(ScreenCoordinate coord) = 0;
34-
public:
35-
ViewElement(decltype(rect) rect);
36-
virtual ~ViewElement();
37-
38-
virtual decltype(rect) getRect() const;
39-
virtual bool containsPoint(ScreenCoordinate coord) const;
40-
virtual bool handleClick(ScreenCoordinate coord);
41-
virtual void render() = 0;
42-
};
43-
4421
/**
4522
* The class in charge of drawing the view to the screen, using OpenGL calls.
4623
*/
4724
class GameView {
4825
private:
4926
GameBoard& model;
50-
27+
5128
std::map<int, std::unique_ptr<ViewElement>> viewElements;
5229
std::vector<ScreenCoordinate> pointsOfInterest;
5330

5431
void highlightPoint(ScreenCoordinate & coord);
55-
32+
5633
std::string controlStateText;
5734

5835
GameView(const GameView& o) = delete;
5936
GameView& operator=(const GameView& o) = delete;
60-
37+
6138
public:
6239
GameView(GameBoard&);
6340
~GameView();
64-
41+
6542
void render();
6643
bool acceptInput(SDL_Event& event);
67-
68-
void setControlStateText(std::string newText);
6944

45+
void setControlStateText(std::string newText);
7046

7147
void addPointOfInterest(ScreenCoordinate);
7248
void clearPointsOfInterest();
7349
void addElement(std::unique_ptr<ViewElement> element);
7450
void addElement(int priority, std::unique_ptr<ViewElement>);
75-
7651

7752
std::unique_ptr<ViewElement> removeElement(int priority);
7853
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
7954
std::unique_ptr<ViewElement> removeElement(const ViewElement&);
80-
81-
void drawCardCount(std::string font, int fontSize);
55+
56+
void drawCardCount(std::string font, int fontSize);
8257
void drawResourceCount(std::string font, int fontSize);
83-
bool showTotals;
58+
bool showTotals;
8459
};
8560

8661
/**
8762
* A visitor of the GameBoard hierarchy that draws the entire model.
8863
*/
89-
class DrawingGameVisitor : public GameVisitor {
64+
class DrawingGameVisitor: public GameVisitor {
9065
private:
9166
GameView& view;
92-
67+
9368
DrawingGameVisitor(const DrawingGameVisitor& o) = delete;
9469
DrawingGameVisitor& operator=(const DrawingGameVisitor& o) = delete;
9570
public:
9671
DrawingGameVisitor(GameView& view);
9772
~DrawingGameVisitor();
98-
73+
9974
virtual void visit(GameBoard&);
10075
virtual void visit(Road&);
10176
virtual void visit(Settlement&);
@@ -107,147 +82,4 @@ class DrawingGameVisitor : public GameVisitor {
10782
virtual void visit(Wonder&);
10883
};
10984

110-
111-
/**
112-
* A view element that is invisible and calls a callback function when it is clicked.
113-
*/
114-
class ViewButton : public ViewElement {
115-
private:
116-
std::function<bool(ScreenCoordinate)> action;
117-
118-
ViewButton(const ViewButton& vb) = delete;
119-
ViewButton& operator=(const ViewButton&) = delete;
120-
protected:
121-
virtual bool clicked(ScreenCoordinate coord);
122-
public:
123-
ViewButton(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect);
124-
virtual ~ViewButton();
125-
126-
virtual void render();
127-
};
128-
129-
/**
130-
* Constructs a ViewButton using the same parameters as the ViewButton. Exists because template inference exists only
131-
* for functions, not classes.
132-
* @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
133-
* @param rect The location on screen that the invisible button receives clicks from.
134-
* @return An owning unique pointer to the constructed view button.
135-
*/
136-
template<class Fn>
137-
std::unique_ptr<ViewElement> makeViewButton(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
138-
return std::unique_ptr<ViewElement>(new ViewButton(fn, rect));
139-
}
140-
141-
/**
142-
* A view element drawn as a solid color that has a callback function that is called when it is clicked.
143-
*/
144-
class ViewButtonColor : public ViewButton {
145-
private:
146-
std::tuple<float, float, float> color;
147-
148-
ViewButtonColor(const ViewButtonColor& vb) = delete;
149-
ViewButtonColor& operator=(const ViewButtonColor& vb) = delete;
150-
public:
151-
ViewButtonColor(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color);
152-
virtual ~ViewButtonColor();
153-
154-
virtual void render();
155-
};
156-
157-
158-
159-
160-
161-
/**
162-
* Constructs a ViewButtonColor using the same parameters as the ViewButtonColor. Exists because template inference exists only
163-
* for functions, not classes.
164-
* @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
165-
* @param rect The location on screen to draw to and receive clicks from.
166-
* @param color The color to draw the button. RGB floats from 0 to 1 for intensity.
167-
* @return An owning unique pointer to the constructed view button.
168-
*/
169-
template<class Fn>
170-
std::unique_ptr<ViewElement> makeViewButtonColor(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color) {
171-
return std::unique_ptr<ViewElement>(new ViewButtonColor(fn, rect, color));
172-
}
173-
174-
/**
175-
* A view element drawn as some text on the screen that has a callback function when it is clicked.
176-
*/
177-
class ViewButtonText : public ViewButton {
178-
private:
179-
GLuint texture;
180-
181-
ViewButtonText(const ViewButtonText& vb) = delete;
182-
ViewButtonText& operator=(const ViewButtonText& vb) = delete;
183-
public:
184-
ViewButtonText(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text);
185-
virtual ~ViewButtonText();
186-
187-
void setText(const std::string& font, int fontSize, const std::string& text);
188-
189-
virtual void render();
190-
};
191-
192-
/**
193-
* Constructs a ViewButtonText using the same parameters as the ViewButtonText. Exists because template inference exists only
194-
* for functions, not classes.
195-
* @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
196-
* @param rect The location on screen to draw to and receive clicks from.
197-
* @param font The path to the font to use to draw the text.
198-
* @param fontSize The font size of the text.
199-
* @param text The text to render.
200-
*/
201-
template<class Fn>
202-
std::unique_ptr<ViewElement> makeViewButtonText(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text) {
203-
return std::unique_ptr<ViewElement>(new ViewButtonText(fn, rect, font, fontSize, text));
204-
}
205-
206-
class TradingView : public ViewElement {
207-
private:
208-
std::string initiating;
209-
std::string receiving;
210-
211-
ViewButtonText trade;
212-
ViewButtonText cancel;
213-
214-
std::array<int, 5> offer;
215-
216-
TradingView(TradingView& o) = delete;
217-
TradingView& operator=(TradingView& o) = delete;
218-
protected:
219-
virtual bool clicked(ScreenCoordinate coord);
220-
public:
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);
222-
virtual ~TradingView();
223-
224-
void render();
225-
};
226-
227-
228-
class ConfirmationDialogue : public ViewElement {
229-
private:
230-
ScreenCoordinate topLeft;
231-
ScreenCoordinate bottomRight;
232-
233-
std::string message;
234-
235-
std::unique_ptr<ViewElement> confirmButton;
236-
std::unique_ptr<ViewElement> cancelButton;
237-
238-
protected:
239-
virtual bool clicked(ScreenCoordinate coord);
240-
241-
public:
242-
ConfirmationDialogue(std::function<bool(ScreenCoordinate)> confirm_action, std::function<bool(ScreenCoordinate)> cancel_action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message);
243-
void render();
244-
};
245-
246-
template<class Fn>
247-
std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn, Fn cancel_fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message) {
248-
return std::unique_ptr<ViewElement>(new ConfirmationDialogue(confirm_fn, cancel_fn, rect, message));
249-
}
250-
251-
252-
25385
#endif

include/GameVisitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class GameDice;
1212
class Wonder;
1313

1414
/**
15-
* A class to be extended with callbacks to handle the different classes in the model.
15+
* A class to be extended with callbacks to handle the different classes in the model.
16+
* Specific subclasses of this visitor pattern are used in Serialization and GameView
1617
*/
1718
class GameVisitor {
1819
private:

include/Player.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ class Player {
7474

7575
std::tuple<float, float, float> getColor() const;
7676

77-
int getVictoryPointsWithoutCards();
78-
int getVictoryPointCards();
79-
8077
int getDevCardsInHand();
8178

8279
bool buyCard(DevCardType card);

0 commit comments

Comments
 (0)