Skip to content

Commit 4bb1bd1

Browse files
Kyle GrageKyle Grage
authored andcommitted
Update wonder serialization and gameview
1 parent 175d16a commit 4bb1bd1

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

include/GameView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class DrawingGameVisitor : public GameVisitor {
7979
virtual void visit(Player&);
8080
virtual void visit(ResourceTile&);
8181
virtual void visit(DevelopmentCard&);
82+
virtual void visit(Wonder&);
8283
};
8384

8485
/**
@@ -155,4 +156,4 @@ std::unique_ptr<ViewElement> makeViewButtonColor(Fn fn, std::pair<ScreenCoordina
155156
return std::unique_ptr<ViewElement>(new ViewButtonColor<Fn>(fn, rect, color));
156157
}
157158

158-
#endif
159+
#endif

include/GameVisitor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class City;
99
class Player;
1010
class DevelopmentCard;
1111
class Wonder;
12-
class CornerPiece;
1312

1413
/**
1514
* A class to be extended with callbacks to handle the different classes in the model.
@@ -31,7 +30,6 @@ class GameVisitor {
3130
virtual void visit(ResourceTile&) = 0;
3231
virtual void visit(DevelopmentCard&) = 0;
3332
virtual void visit(Wonder&) = 0;
34-
virtual void visit(CornerPiece&) = 0;
3533
};
3634

3735
#endif

include/Serialization.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ class XMLVisitor : public GameVisitor {
3333
virtual void visit(Player&);
3434
virtual void visit(ResourceTile&);
3535
virtual void visit(DevelopmentCard&);
36+
virtual void visit(Wonder&);
3637

3738
const tinyxml2::XMLDocument& getXMLDoc() const;
3839
};
3940

4041
Coordinate xmlElementToCoord(const tinyxml2::XMLElement& element);
4142

42-
#endif
43+
#endif

src/GameView.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ void DrawingGameVisitor::visit(City& city) {
220220
glEnd();
221221
}
222222

223+
/**
224+
* Draw a wonder. Right now is just a square.
225+
* @param wonder The city to draw.
226+
*/
227+
void DrawingGameVisitor::visit(Wonder& wonder) {
228+
static const auto wonderRadius = 0.06;
229+
230+
auto centerScreenPos = coordToScreen(wonder.getLocation());
231+
232+
glBindTexture(GL_TEXTURE_2D, 0);
233+
glColor3d(0., 0., 0.);
234+
glBegin(GL_QUADS);
235+
glVertex2d(centerScreenPos.first + wonderRadius, centerScreenPos.second + wonderRadius);
236+
glVertex2d(centerScreenPos.first + wonderRadius, centerScreenPos.second - wonderRadius);
237+
glVertex2d(centerScreenPos.first - wonderRadius, centerScreenPos.second - wonderRadius);
238+
glVertex2d(centerScreenPos.first - wonderRadius, centerScreenPos.second + wonderRadius);
239+
glEnd();
240+
}
241+
223242
/**
224243
* Draw a player.
225244
* @param player The player to draw.

src/Serialization.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ void XMLVisitor::visit(City& city) {
111111
citiesElement->InsertEndChild(newCityElement);
112112
}
113113

114+
/**
115+
* Serialize a wonder.
116+
* @param wonder The city to serialize.
117+
*/
118+
void XMLVisitor::visit(Wonder& wonder) {
119+
if(!xmldoc.RootElement()->FirstChildElement("wonders")) {
120+
xmldoc.RootElement()->InsertEndChild(xmldoc.NewElement("wonders"));
121+
}
122+
XMLElement* wondersElement = xmldoc.RootElement()->FirstChildElement("wonders");
123+
XMLElement* newWonderElement = xmldoc.NewElement("wonder");
124+
125+
XMLElement* ownerElement = xmldoc.NewElement("owner");
126+
ownerElement->InsertEndChild(xmldoc.NewText(wonder.getOwner().getName().c_str()));
127+
newWonderElement->InsertEndChild(ownerElement);
128+
129+
newWonderElement->InsertEndChild(coordinateElement(wonder.getLocation()));
130+
131+
wondersElement->InsertEndChild(newWonderElement);
132+
}
133+
114134
/**
115135
* Serialize a player.
116136
* @param player The player to serialize.

0 commit comments

Comments
 (0)