Skip to content

Commit 86818c5

Browse files
committed
we said sketchy UI code was the plan right?
1 parent 8b764d6 commit 86818c5

File tree

10 files changed

+158
-2
lines changed

10 files changed

+158
-2
lines changed

include/GameBoard.h

Lines changed: 4 additions & 1 deletion
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,6 +29,9 @@ 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

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: 1 addition & 0 deletions
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(GameDice&);
8283
};
8384

8485
/**

include/GameVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Road;
88
class City;
99
class Player;
1010
class DevelopmentCard;
11+
class GameDice;
1112

1213
/**
1314
* A class to be extended with callbacks to handle the different classes in the model.
@@ -28,6 +29,7 @@ class GameVisitor {
2829
virtual void visit(Player&) = 0;
2930
virtual void visit(ResourceTile&) = 0;
3031
virtual void visit(DevelopmentCard&) = 0;
32+
virtual void visit(GameDice&) = 0;
3133
};
3234

3335
#endif

include/Serialization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class XMLVisitor : public GameVisitor {
3131
virtual void visit(Player&);
3232
virtual void visit(ResourceTile&);
3333
virtual void visit(DevelopmentCard&);
34+
virtual void visit(GameDice&);
3435

3536
const tinyxml2::XMLDocument& getXMLDoc() const;
3637
};

resources/catan_dice_new.bmp

6 MB
Binary file not shown.

src/GameBoard.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tinyxml2.h"
1414

1515
#include "CornerPiece.h"
16+
#include "GameDice.h"
1617

1718
#include "City.h"
1819

@@ -39,6 +40,10 @@ GameBoard::GameBoard(vector<unique_ptr<Player>>&& players) : players(std::move(p
3940
const static vector<int> boardRolls = {0, 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12};
4041

4142
bool valid = false;
43+
44+
45+
46+
4247

4348
const static Coordinate center {0, 4};
4449

@@ -617,6 +622,7 @@ void GameBoard::accept(GameVisitor& visitor) {
617622
it->accept(visitor);
618623
}
619624
}
625+
dice.accept(visitor);
620626
}
621627

622628
/**
@@ -734,7 +740,8 @@ std::pair<int, int> GameBoard::startTurn()
734740
int die2 = std::rand() % 6 + 1;
735741
int roll = die1+die2;
736742
std::cout << "\nDie 1: " << die1 << "\nDie 2: " << die2 << "\nRoll: " << roll <<"\n";
737-
743+
dice.setFirst(die1);
744+
dice.setSecond(die2);
738745
if (roll==7)
739746
enableRobber();
740747

src/GameDice.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "GameDice.h"
2+
#include "GameVisitor.h"
3+
4+
int GameDice::getFirst(){
5+
return first;
6+
}
7+
8+
int GameDice::getSecond(){
9+
return second;
10+
}
11+
12+
void GameDice::setFirst(int newFirst){
13+
first = newFirst;
14+
}
15+
16+
void GameDice::setSecond(int newSecond){
17+
second = newSecond;
18+
}
19+
20+
void GameDice::accept(GameVisitor& visitor) {
21+
visitor.visit(*this);
22+
}

src/GameView.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ void DrawingGameVisitor::visit(GameBoard& model) {
143143

144144
}
145145

146+
147+
146148
/**
147149
* Draw a road.
148150
* @param road The road to draw.
@@ -241,18 +243,103 @@ void drawTexturedCircle(std::pair<float, float> texCenter, float texRadius, std:
241243
double angle = ((double) i) * (2. * M_PI) / (double)articulation;
242244
double tangle = ((double) -i) * (2. * M_PI) / (double)articulation;
243245
texCoordPair({texCenter.first + texRadius * std::cos(tangle), texCenter.second + texRadius * std::sin(tangle)});
246+
//std::cout << texCenter.first + texRadius << "\n";
244247
glVertex2d(screenCenter.first + (screenRadius * std::cos(angle)), screenCenter.second + (screenRadius * std::sin(angle)));
248+
//std::cout << screenCenter.first + (screenRadius * std::cos(angle));
249+
245250
}
246251
glEnd();
247252
}
248253

254+
void drawTexturedRectangle(std::pair<float, float> texTopLeft, float sideLength, std::pair<float, float> screenTopLeft, float screenSideLength) {
255+
256+
static const GLuint diceTextures = loadImageAsTexture("resources/catan_dice_new.bmp");
257+
glBindTexture(GL_TEXTURE_2D, diceTextures);
258+
259+
glBegin(GL_QUADS);
260+
261+
262+
263+
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + 0.0f});
264+
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + 0.0f);
265+
266+
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + 0.0f});
267+
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + 0.0f);
268+
269+
270+
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + sideLength});
271+
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + screenSideLength);
272+
273+
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
274+
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
275+
276+
277+
//redraw the image for reasons
278+
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + sideLength});
279+
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + screenSideLength);
280+
281+
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + sideLength});
282+
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + screenSideLength);
283+
284+
texCoordPair({texTopLeft.first + sideLength, texTopLeft.second + 0.0f});
285+
glVertex2d(screenTopLeft.first + screenSideLength, screenTopLeft.second + 0.0f);
286+
287+
texCoordPair({texTopLeft.first + 0.0f, texTopLeft.second + 0.0f});
288+
glVertex2d(screenTopLeft.first + 0.0f, screenTopLeft.second + 0.0f);
289+
290+
291+
292+
293+
glEnd();
294+
295+
296+
glBindTexture(GL_TEXTURE_2D, 0);
297+
298+
299+
300+
}
301+
302+
void DrawingGameVisitor::visit(GameDice& dice) {
303+
304+
305+
306+
307+
/*static const std::map<int, std::pair<float, float>> topLeftOffset = {
308+
make_pair(1, make_pair(4.f, 8.f)),
309+
make_pair(2, make_pair(134.f, 8.f)),
310+
make_pair(3, make_pair(264.f, 8.f)),
311+
make_pair(4, make_pair(4.f, 142.f)),
312+
make_pair(5, make_pair(134.f, 142.f)),
313+
make_pair(6, make_pair(264.f, 142.f))
314+
};*/
315+
/*
316+
drawTexturedRectangle(topLeftOffset.find(dice.getFirst())->second, 96.f,
317+
make_pair(.8f, .9f), 0.03);
318+
*/
319+
320+
//drawTexturedRectangle(make_pair(134.f, 8.f), 96.f, make_pair(.8f, .9f), 0.03);
321+
322+
//drawTexturedRectangle(topLeftOffset.find(dice.getSecond())->second, 96.f,
323+
//make_pair(.84f, .9f), 0.03);
324+
325+
drawTexturedRectangle(make_pair(4.f, 8.f), 1000.f, make_pair(.7f, .9f), 0.03);
326+
327+
328+
329+
330+
331+
//std::cout << dice.getFirst() << "\n";
332+
333+
}
334+
249335
/**
250336
* Draw a resource tile.
251337
* @param tile The tile to draw.
252338
*/
253339
void DrawingGameVisitor::visit(ResourceTile& tile) {
254340
Coordinate coord = tile.getLocation();
255341
static const GLuint tileTextures = loadImageAsTexture("resources/catan_sprite_sheet.bmp");
342+
256343
glBindTexture(GL_TEXTURE_2D, tileTextures);
257344
static const std::map<resourceType, pair<float, float>> topRightPoints = {
258345
make_pair(WOOD, make_pair(260.f, 17.f)),
@@ -307,6 +394,8 @@ void DrawingGameVisitor::visit(ResourceTile& tile) {
307394
drawTexturedCircle(numberTexPoints.find(tile.getDiceValue())->second, radius, coordToScreen(coord), 0.04);
308395
}
309396
glBindTexture(GL_TEXTURE_2D, 0);
397+
398+
310399
}
311400

312401
/**

src/Serialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ void XMLVisitor::visit(ResourceTile& tile) {
188188
tilesElement->InsertEndChild(newTileElement);
189189
}
190190

191+
void XMLVisitor::visit(GameDice& dice){
192+
193+
}
191194
/**
192195
* Serialize a development card.
193196
* @param card The card to serialize.

0 commit comments

Comments
 (0)