Skip to content

Commit 0fa473a

Browse files
committed
added robber, changed resources to be a map of resourcetiles
2 parents 788a1e8 + 235bb71 commit 0fa473a

23 files changed

+782
-526
lines changed

include/Deck.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
99
#define DECK_H_
1010

1111
#include <vector>
12+
#include <ctime>
1213
#include <algorithm>
1314
#include "DevelopmentCard.h"
1415

1516
class Deck {
1617

1718
private:
1819
std::vector<DevelopmentCard*> deck;
20+
std::vector<DevelopmentCard*> discardPile;
21+
22+
void shuffleDeck();
23+
void reshuffleDeck();
1924

2025
public:
2126
Deck();
2227
virtual ~Deck();
2328

2429
int getSize();
2530
DevelopmentCard* drawCard();
31+
void discard(DevelopmentCard* toDiscard);
2632
};
2733

2834
#endif /* DECK_H_ */

include/GameBoard.h

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,51 +22,70 @@ class GameVisitor;
2222
class GameBoard {
2323
private:
2424
std::map<Coordinate, std::unique_ptr<CornerPiece>> corners;
25+
2526
std::map<Coordinate, std::unique_ptr<ResourceTile>> resources;
27+
28+
29+
std::map<Coordinate, std::vector<std::shared_ptr<Road>>> roads;
30+
2631
std::vector<std::unique_ptr<Player>> players;
2732
Coordinate robber;
2833

2934

3035
void addResource(int x, int y, resourceType res, int val);
3136
bool checkRolls(int* rolls);
3237

33-
std::map<Coordinate, std::vector<std::shared_ptr<Road>>> roads;
38+
bool isValidBoard() const;
3439

35-
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner);
36-
bool outOfBounds(const Coordinate& coord);
37-
bool roadExists(Coordinate start, Coordinate end);
38-
bool isRoadConnectionPoint(Coordinate start, Coordinate end, Player& Owner);
40+
bool verifyRoadPlacement(Coordinate start, Coordinate end, Player& Owner) const;
41+
bool outOfBounds(const Coordinate& coord) const;
42+
bool roadExists(Coordinate start, Coordinate end) const;
43+
bool isRoadConnectionPoint(Coordinate point, Player& Owner) const;
3944

4045
int constructBoardFromFile(std::ifstream &file);
4146
int constructFileFromBoard(std::ofstream &file);
4247

4348
void removeRoadEnd(std::shared_ptr<Road> startRoad);
44-
int FindLongestRoad_FromPoint(Coordinate curr, Player & owner, std::map<Coordinate, bool>& marked, int length);
45-
49+
int FindLongestRoad_FromPoint(Coordinate curr, const Player & owner, std::map<Coordinate, bool>& marked, std::map<Road*, bool>& markedRoads, int length) const;
50+
51+
void createRing(Coordinate topRight, int sideLength, std::vector<resourceType>& resources, std::vector<int>& rolls);
52+
void insertTile(Coordinate location, std::vector<resourceType>& resources, std::vector<int>& rolls);
4653
public:
4754
GameBoard(std::vector<std::unique_ptr<Player>>&& players);
55+
GameBoard(std::vector<std::unique_ptr<Player>>&& players, const std::map<Coordinate, std::pair<resourceType, int>>& resourceLocations);
4856
GameBoard(std::istream& in);
4957
GameBoard(GameBoard&) = delete;
5058
~GameBoard();
5159
GameBoard& operator=(GameBoard&) = delete;
5260

5361
void save(std::ostream& out);
5462

63+
5564
const std::map<Coordinate, std::unique_ptr<ResourceTile>>& getResources() const;
56-
std::shared_ptr<Road> getRoad(Coordinate start, Coordinate end);
65+
66+
67+
68+
const std::shared_ptr<Road> getRoad(Coordinate start, Coordinate end) const;
69+
5770

58-
int FindLongestRoad(Player & owner);
71+
int FindLongestRoad(const Player & owner) const;
5972

6073
std::vector<Settlement*> GetNeighboringSettlements(Coordinate location) const;
6174
std::vector<CornerPiece*> GetNeighboringCorners(Coordinate location) const;
6275

6376

77+
6478
void PlaceSettlement(Coordinate location, Player& Owner);
6579
void UpgradeSettlement(Coordinate location);
66-
void PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
80+
//void PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
81+
82+
83+
bool buyRoad(Coordinate start, Coordinate end, Player& Owner);
6784

6885

69-
void init_resources();
86+
//void PlaceSettlement(Coordinate location, Player& Owner);
87+
void PlaceCity(Coordinate location, Player& Owner);
88+
bool PlaceRoad(Coordinate start, Coordinate end, Player& Owner);
7089

7190
void accept(GameVisitor& visitor);
7291

include/GameController.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef GAME_CONTROLLER_H
2+
#define GAME_CONTROLLER_H
3+
4+
class GameBoard;
5+
6+
class GameController {
7+
private:
8+
GameBoard& board;
9+
10+
GameController(const GameController& o) : board(o.board) {} //deleted
11+
GameController& operator=(const GameController& o) { return *this; } //deleted
12+
public:
13+
GameController(GameBoard&);
14+
~GameController();
15+
};
16+
17+
#endif

include/GamePiece.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GamePiece {
2323
Coordinate getCoordinates() const;
2424
GameBoard& getBoard();
2525
const GameBoard& getBoard() const;
26-
26+
2727
Coordinate location;
2828

2929
virtual void accept(GameVisitor&) = 0;

include/GameView.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef GAME_VIEW_H
2+
#define GAME_VIEW_H
3+
4+
#include "SDL2/SDL.h"
5+
6+
#include "GameVisitor.h"
7+
8+
class GameBoard;
9+
class GameController;
10+
11+
class GameView {
12+
private:
13+
GameBoard& model;
14+
GameController& controller;
15+
16+
GameView(const GameView& o) : model(o.model), controller(o.controller) {} //deleted
17+
GameView& operator=(const GameView& o) { return *this; } //deleted
18+
public:
19+
GameView(GameBoard&, GameController&);
20+
~GameView();
21+
22+
void render();
23+
bool acceptInput(SDL_Event& event);
24+
};
25+
26+
class DrawingGameVisitor : public GameVisitor {
27+
private:
28+
GameView& view;
29+
30+
DrawingGameVisitor(const DrawingGameVisitor& o) : view(o.view) {} //deleted
31+
DrawingGameVisitor& operator=(const DrawingGameVisitor& o) { return *this; } //deleted
32+
public:
33+
DrawingGameVisitor(GameView& view);
34+
~DrawingGameVisitor();
35+
36+
virtual void visit(GameBoard&);
37+
virtual void visit(Road&);
38+
virtual void visit(Settlement&);
39+
virtual void visit(City&);
40+
virtual void visit(Player&);
41+
virtual void visit(ResourceTile&);
42+
virtual void visit(DevelopmentCard&);
43+
};
44+
45+
#endif

include/Player.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,26 @@ class Player {
6565

6666
void playCard(DevelopmentCard* card);
6767

68+
bool canBuyRoad();
69+
bool buyRoad();
70+
6871
bool offerTrade(Player* p, int offer[], int demand[]);
6972
bool recieveOffer(Player* p, int offer[], int demand[]);
7073
bool acceptOffer(Player* p, int offer[], int demand[]);
7174

7275
bool checkResources(int resourceList[]);
7376

74-
7577
int getWood() const;
7678
int getBrick() const;
7779
int getOre() const;
7880
int getWheat() const;
7981
int getWool() const;
8082

81-
void setWood(int resource);
82-
void setBrick(int resource);
83-
void setOre(int resource);
84-
void setWheat(int resource);
85-
void setWool(int resource);
83+
void addWood(int resource);
84+
void addBrick(int resource);
85+
void addOre(int resource);
86+
void addWheat(int resource);
87+
void addWool(int resource);
8688

8789
void addResource(int resourceType, int delta);
8890

include/Renderer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
#ifndef RENDERER_H
22
#define RENDERER_H
33

4+
#include <SDL2/SDL.h>
5+
#include <SDL2/SDL_opengl.h>
6+
#include <GL/gl.h>
7+
48
#include "GameBoard.h"
59
#include "Player.h"
610

711
void renderBoard(const GameBoard& board, const Player& perspective);
812

13+
GLuint loadImageAsTexture(const std::string& name);
14+
15+
std::pair<float, float> coordToScreen(const Coordinate& coord);
16+
17+
void vertexPair(const Coordinate& coord);
18+
19+
void texCoordPair(const std::pair<float, float>& p);
20+
21+
std::pair<float, float> averagePoint(const std::vector<std::pair<float, float>>& points);
22+
923
#endif

include/Road.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ class GameVisitor;
1212

1313
class Road {
1414
private:
15-
bool checkRoad();
16-
15+
Player& owner;
1716
Coordinate start;
1817
Coordinate end;
19-
20-
bool marker;
18+
19+
bool checkRoad();
2120
public:
2221
Road(Coordinate start, Coordinate end, Player& Owner);
2322
Road(Road&) = delete;
@@ -29,15 +28,9 @@ class Road {
2928

3029
bool equals(const Road& otherRoad);
3130
bool equals(const Coordinate& otherStart, const Coordinate& otherEnd);
32-
33-
bool isMarked();
34-
void mark();
35-
void unmark();
3631

3732
Player& getOwner();
3833
const Player& getOwner() const;
39-
40-
Player* owner;
4134

4235
virtual void accept(GameVisitor& visitor);
4336
bool operator==(const Road&) const;

include/UserInput.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Deck.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include <iostream>
99
#include "Deck.h"
1010

11-
Deck::Deck() {
11+
Deck::Deck()
12+
{
1213
// TODO Auto-generated constructor stub
1314
for(int i = 0; i < 15; i++)
1415
{
@@ -35,7 +36,8 @@ Deck::Deck() {
3536
DevelopmentCard* card = new RoadBuildingCard(NULL);
3637
this->deck.push_back(card);
3738
}
38-
39+
40+
shuffleDeck();
3941
}
4042

4143
Deck::~Deck() {
@@ -45,7 +47,14 @@ Deck::~Deck() {
4547
{
4648
delete this->deck.back();
4749
this->deck.pop_back();
48-
std::cout<<":";
50+
//std::cout<<":";
51+
}
52+
53+
while(!this->discardPile.empty())
54+
{
55+
delete this->discardPile.back();
56+
this->discardPile.pop_back();
57+
//std::cout<<":";
4958
}
5059
}
5160

@@ -59,8 +68,37 @@ int Deck::getSize()
5968
DevelopmentCard* Deck::drawCard()
6069
{
6170
if(this->getSize() == 0)
62-
return NULL;
71+
{
72+
reshuffleDeck();
73+
}
74+
75+
if(this->getSize() == 0)
76+
{
77+
return NULL;
78+
}
79+
6380
DevelopmentCard* card = this->deck.back();
6481
this->deck.pop_back();
6582
return card;
6683
}
84+
85+
void Deck::shuffleDeck()
86+
{
87+
std::srand(std::time(0));
88+
random_shuffle(deck.begin(), deck.end());
89+
}
90+
91+
void Deck::reshuffleDeck()
92+
{
93+
while(!discardPile.empty())
94+
{
95+
deck.push_back(discardPile.back());
96+
discardPile.pop_back();
97+
}
98+
shuffleDeck();
99+
}
100+
101+
void Deck::discard(DevelopmentCard* toDiscard)
102+
{
103+
discardPile.push_back(toDiscard);
104+
}

0 commit comments

Comments
 (0)