Skip to content

Commit d232290

Browse files
committed
Merge branch 'DevCardUI2' into DevCardUI3
Conflicts: include/DevelopmentCard.h include/GameBoard.h include/GameController.h include/GameView.h include/Player.h src/Deck.cpp src/DevelopmentCard.cpp src/GameController.cpp src/GameView.cpp src/Player.cpp src/Serialization.cpp src/main.cpp tests/testSerialization.cpp tests/test_DevelopmentCards.cpp tests/test_GameBoard.cpp tests/test_Roads.cpp
2 parents c949c14 + aa451ad commit d232290

25 files changed

+1576
-180
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ warsofcatan
1919
*.test
2020
/Default
2121
*.wocs
22+
23+
documentation/*
24+
/Debug

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ language: cpp
22
before_install:
33
- sudo add-apt-repository ppa:antumdeluge/sdl2 -y
44
- sudo apt-get update -y
5-
- sudo apt-get install libsdl2 libsdl2-dev -y
5+
- sudo apt-get install libsdl2 libsdl2-dev libsdl2-ttf libsdl2-ttf-dev -y
66
script: make tests

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 -lGL -lGLU
10+
export CXXFLAGS := -g -I$(INCL_HOME) -std=c++0x -I/usr/include/SDL -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)
@@ -25,4 +25,4 @@ tests: $(EXECUTABLE)
2525
.PHONY: clean
2626
clean:
2727
rm -f $(EXECUTABLE)
28-
rm -f obj/*.o
28+
rm -f obj/*.o

include/GameBoard.h

Lines changed: 7 additions & 2 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

@@ -31,6 +31,9 @@ class GameBoard {
3131

3232
std::map<Coordinate, std::unique_ptr<ResourceTile>> resources;
3333

34+
GameDice dice;
35+
36+
3437

3538
std::map<Coordinate, std::vector<std::shared_ptr<Road>>> roads;
3639

@@ -43,6 +46,7 @@ class GameBoard {
4346

4447
bool isValidBoard() const;
4548

49+
4650
bool outOfBounds(const Coordinate& coord) const;
4751
bool roadExists(Coordinate start, Coordinate end) const;
4852
bool isRoadConnectionPoint(Coordinate point, Player& Owner) const;
@@ -90,14 +94,15 @@ class GameBoard {
9094

9195
void PlaceSettlement(Coordinate location, Player& Owner);
9296
void UpgradeSettlement(Coordinate location);
93-
//void PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
97+
void UpgradeToWonder(Coordinate location);
9498

9599

96100
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
97101
bool buyRoad(Coordinate start, Coordinate end, Player& Owner);
98102

99103
//void PlaceSettlement(Coordinate location, Player& Owner);
100104
void PlaceCity(Coordinate location, Player& Owner);
105+
void PlaceWonder(Coordinate location, Player& Owner);
101106
bool PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
102107
bool canPlayBuildRoadCard(Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2, Player& Owner);
103108

include/GameController.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
#include "Util.h"
55
#include <vector>
66

7+
#include <array>
8+
79
class GameBoard;
810
class ClickCoordinateEvent;
911
class GameView;
12+
class Player;
1013

1114

1215
enum ControlState {BASESTATE, MODALSTATE, BUILDROAD, BUILDSETTLEMENT, ROBBER,
@@ -47,7 +50,7 @@ class GameController {
4750
void pushState(ControlState);
4851
ControlState getState();
4952
ControlState popState();
50-
53+
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
5154
void storeClick(Coordinate clickCoordinate);
5255
Coordinate getLastClick();
5356
Coordinate getPastClick(int howLongAgo);
@@ -59,6 +62,8 @@ class GameController {
5962

6063

6164

65+
bool handlePlayerClick(ScreenCoordinate, Player&);
66+
bool handleTradeOffer(ScreenCoordinate, Player& initiating, std::array<int, 5>, Player& receiving, std::array<int, 5>);
6267
};
6368

6469
#endif

include/GameDice.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef GAMEDICE_H
2+
#define GAMEDICE_H
3+
4+
5+
6+
7+
8+
class GameVisitor;
9+
10+
class GameDice {
11+
private:
12+
int first;
13+
int second;
14+
15+
16+
public:
17+
int getFirst();
18+
int getSecond();
19+
bool shown;
20+
void setFirst(int newFirst);
21+
void setSecond(int newSecond);
22+
virtual void accept(GameVisitor& visitor);
23+
24+
25+
26+
};
27+
28+
#endif

include/GameView.h

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
#include <vector>
55
#include <memory>
6+
#include <array>
67

78
#include "SDL2/SDL.h"
89
#include "SDL2/SDL_opengl.h"
910
#include "GL/gl.h"
1011

1112
#include "GameVisitor.h"
13+
#include "Renderer.h"
1214
#include "Util.h"
1315

1416
class GameBoard;
@@ -45,26 +47,28 @@ class GameView {
4547
private:
4648
GameBoard& model;
4749

48-
std::vector<std::unique_ptr<ViewElement>> viewElements;
50+
std::map<int, std::unique_ptr<ViewElement>> viewElements;
4951
std::vector<ScreenCoordinate> pointsOfInterest;
5052

5153
void highlightPoint(ScreenCoordinate & coord);
5254

53-
GameView(const GameView& o) : model(o.model) {} //deleted
54-
GameView& operator=(const GameView& o) { return *this; } //deleted
55+
GameView(const GameView& o) = delete;
56+
GameView& operator=(const GameView& o) = delete;
5557
public:
5658
GameView(GameBoard&);
5759
~GameView();
5860

5961
void render();
6062
bool acceptInput(SDL_Event& event);
6163

62-
void addElement(std::unique_ptr<ViewElement>);
63-
bool removeElement(ViewElement*);
64-
bool removeLastElement();
6564

6665
void addPointOfInterest(ScreenCoordinate);
6766
void clearPointsOfInterest();
67+
void addElement(int priority, std::unique_ptr<ViewElement>);
68+
69+
std::unique_ptr<ViewElement> removeElement(int priority);
70+
std::unique_ptr<ViewElement> removeElement(const ViewElement*);
71+
std::unique_ptr<ViewElement> removeElement(const ViewElement&);
6872
};
6973

7074
/**
@@ -74,8 +78,8 @@ class DrawingGameVisitor : public GameVisitor {
7478
private:
7579
GameView& view;
7680

77-
DrawingGameVisitor(const DrawingGameVisitor& o) : view(o.view) {} //deleted
78-
DrawingGameVisitor& operator=(const DrawingGameVisitor& o) { return *this; } //deleted
81+
DrawingGameVisitor(const DrawingGameVisitor& o) = delete;
82+
DrawingGameVisitor& operator=(const DrawingGameVisitor& o) = delete;
7983
public:
8084
DrawingGameVisitor(GameView& view);
8185
~DrawingGameVisitor();
@@ -87,28 +91,27 @@ class DrawingGameVisitor : public GameVisitor {
8791
virtual void visit(Player&);
8892
virtual void visit(ResourceTile&);
8993
virtual void visit(DevelopmentCard&);
94+
virtual void visit(GameDice&);
95+
virtual void visit(Wonder&);
9096
};
9197

9298

9399
/**
94100
* A view element that is invisible and calls a callback function when it is clicked.
95101
*/
96-
template<class Fn>
97102
class ViewButton : public ViewElement {
98103
private:
99-
Fn action;
104+
std::function<bool(ScreenCoordinate)> action;
100105

101-
ViewButton(const ViewButton& vb) : ViewElement(vb) {} //deleted
102-
ViewButton& operator=(const ViewButton&) { return *this; } //deleted
106+
ViewButton(const ViewButton& vb) = delete;
107+
ViewButton& operator=(const ViewButton&) = delete;
103108
protected:
104-
virtual bool clicked(ScreenCoordinate coord) {
105-
return action(coord);
106-
}
109+
virtual bool clicked(ScreenCoordinate coord);
107110
public:
108-
ViewButton(Fn action, std::pair<ScreenCoordinate, ScreenCoordinate> rect) : ViewElement(rect), action(action) {}
109-
virtual ~ViewButton() {}
111+
ViewButton(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect);
112+
virtual ~ViewButton();
110113

111-
virtual void render() {}
114+
virtual void render();
112115
};
113116

114117
/**
@@ -120,35 +123,23 @@ class ViewButton : public ViewElement {
120123
*/
121124
template<class Fn>
122125
std::unique_ptr<ViewElement> makeViewButton(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
123-
return std::unique_ptr<ViewElement>(new ViewButton<Fn>(fn, rect));
126+
return std::unique_ptr<ViewElement>(new ViewButton(fn, rect));
124127
}
125128

126129
/**
127130
* A view element drawn as a solid color that has a callback function that is called when it is clicked.
128131
*/
129-
template<class Fn>
130-
class ViewButtonColor : public ViewButton<Fn> {
132+
class ViewButtonColor : public ViewButton {
131133
private:
132134
std::tuple<float, float, float> color;
133135

134-
ViewButtonColor(const ViewButtonColor& vb) : ViewElement(vb) {} //deleted
135-
ViewButtonColor& operator=(const ViewButtonColor& vb) { return *this; }
136+
ViewButtonColor(const ViewButtonColor& vb) = delete;
137+
ViewButtonColor& operator=(const ViewButtonColor& vb) = delete;
136138
public:
137-
ViewButtonColor(Fn action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color) : ViewButton<Fn>(action, rect), color(color) {}
138-
virtual ~ViewButtonColor() {}
139+
ViewButtonColor(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color);
140+
virtual ~ViewButtonColor();
139141

140-
virtual void render() {
141-
glBindTexture(GL_TEXTURE_2D, 0);
142-
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
143-
auto topLeft = ViewElement::getRect().first;
144-
auto bottomRight = ViewElement::getRect().second;
145-
glBegin(GL_QUADS);
146-
glVertex2f(topLeft.first, topLeft.second);
147-
glVertex2f(bottomRight.first, topLeft.second);
148-
glVertex2f(bottomRight.first, bottomRight.second);
149-
glVertex2f(topLeft.first, bottomRight.second);
150-
glEnd();
151-
}
142+
virtual void render();
152143
};
153144

154145
template<class Fn>
@@ -249,7 +240,60 @@ std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn, Fn cancel_f
249240
*/
250241
template<class Fn>
251242
std::unique_ptr<ViewElement> makeViewButtonColor(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color) {
252-
return std::unique_ptr<ViewElement>(new ViewButtonColor<Fn>(fn, rect, color));
243+
return std::unique_ptr<ViewElement>(new ViewButtonColor(fn, rect, color));
253244
}
254245

246+
/**
247+
* A view element drawn as some text on the screen that has a callback function when it is clicked.
248+
*/
249+
class ViewButtonText : public ViewButton {
250+
private:
251+
GLuint texture;
252+
253+
ViewButtonText(const ViewButtonText& vb) = delete;
254+
ViewButtonText& operator=(const ViewButtonText& vb) = delete;
255+
public:
256+
ViewButtonText(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text);
257+
virtual ~ViewButtonText();
258+
259+
void setText(const std::string& font, int fontSize, const std::string& text);
260+
261+
virtual void render();
262+
};
263+
264+
/**
265+
* Constructs a ViewButtonText using the same parameters as the ViewButtonText. Exists because template inference exists only
266+
* for functions, not classes.
267+
* @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
268+
* @param rect The location on screen to draw to and receive clicks from.
269+
* @param font The path to the font to use to draw the text.
270+
* @param fontSize The font size of the text.
271+
* @param text The text to render.
272+
*/
273+
template<class Fn>
274+
std::unique_ptr<ViewElement> makeViewButtonText(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text) {
275+
return std::unique_ptr<ViewElement>(new ViewButtonText(fn, rect, font, fontSize, text));
276+
}
277+
278+
class TradingView : public ViewElement {
279+
private:
280+
Player& initiating;
281+
Player& receiving;
282+
283+
ViewButtonText trade;
284+
ViewButtonText cancel;
285+
286+
std::array<int, 5> offer;
287+
288+
TradingView(TradingView& o) = delete;
289+
TradingView& operator=(TradingView& o) = delete;
290+
protected:
291+
virtual bool clicked(ScreenCoordinate coord);
292+
public:
293+
TradingView(Player& initiating, Player& receiving, std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade, std::function<bool(ScreenCoordinate)> cancel, std::array<int, 5> offer);
294+
virtual ~TradingView();
295+
296+
void render();
297+
};
298+
255299
#endif

0 commit comments

Comments
 (0)