Skip to content

Commit 80d8ad6

Browse files
committed
Made an initial board set up and gave Players colors
1 parent 4efaad0 commit 80d8ad6

File tree

7 files changed

+76
-20
lines changed

7 files changed

+76
-20
lines changed

include/GameBoard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class GameBoard {
7373
~GameBoard();
7474
GameBoard& operator=(GameBoard&) = delete;
7575

76+
void initializeGame();
77+
7678
void save(std::ostream& out);
7779

7880
ResourceTile& getResourceTile(Coordinate location) const;

include/Player.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class Player {
4848
int resources[5];
4949
int tradeModifiers[5];
5050

51+
float color[3];
52+
5153

5254
void tradeWithBank(std::array<int, 5> offer, std::array<int, 5> demand);
5355

@@ -69,6 +71,7 @@ class Player {
6971
void setLongestRoad(bool);
7072
void setLongestRoadSize(int);
7173

74+
float* getColor();
7275

7376
int getVictoryPointsWithoutCards();
7477
int getVictoryPointCards();
@@ -127,7 +130,7 @@ class Player {
127130
int getWheat() const;
128131
int getWool() const;
129132

130-
void giveDevCardBoon();
133+
void setStartingValues();
131134

132135
int getDevelopmentCards(int card_type) const;
133136
int getVictoryCards() const;

src/GameBoard.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,30 @@ void GameBoard::endTurn()
326326
startTurn();
327327
}
328328

329+
void GameBoard::initializeGame(){
330+
PlaceSettlement(Coordinate(-1,2), getPlayer(0));
331+
PlaceSettlement(Coordinate(1,1), getPlayer(0));
332+
getPlayer(0).setStartingValues();
333+
334+
PlaceSettlement(Coordinate(-2,4), getPlayer(1));
335+
PlaceSettlement(Coordinate(-2,6), getPlayer(1));
336+
getPlayer(1).setStartingValues();
337+
338+
PlaceSettlement(Coordinate(-1,7), getPlayer(2));
339+
PlaceSettlement(Coordinate(1,6), getPlayer(2));
340+
getPlayer(2).setStartingValues();
341+
342+
PlaceSettlement(Coordinate(2,4), getPlayer(3));
343+
PlaceSettlement(Coordinate(2,2), getPlayer(3));
344+
getPlayer(3).setStartingValues();
345+
346+
for(int i = 1; i < 13; i++){
347+
payoutResources(i);
348+
}
349+
350+
}
351+
352+
329353
/**
330354
* @return The no of Victory points needed to win the game
331355
*/

src/GameController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ GameController::GameController(GameBoard& model, GameView& view) : model(model),
2929

3030
auto playerTopY = 0.9;
3131
for(auto i = 0; i < model.getNoOfPlayers(); i++) {
32-
auto width = 0.2;
32+
auto width = 0.15;
3333
Player& player = model.getPlayer(i);
34-
view.addElement(makeViewButtonText(std::bind(&GameController::handlePlayerClick, this, _1, std::ref(player)), {{1.0 - width, playerTopY - 0.1}, {1.0, playerTopY}}, font, fontSize, player.getName()));
34+
view.addElement(makeViewButtonText(std::bind(&GameController::handlePlayerClick, this, _1, std::ref(player)), {{1.0 - width, playerTopY - 0.05}, {1.0, playerTopY}}, font, fontSize, player.getName()));
3535
playerTopY -= 0.05;
3636
}
3737

src/GameView.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ void DrawingGameVisitor::visit(Road& road) {
415415
auto cosPerp = std::cos(roadPerpAngle);
416416
auto sinPerp = std::sin(roadPerpAngle);
417417

418-
glColor3d(0., 0., 0.);
418+
float* color = road.getOwner().getColor();
419+
glColor3d(color[0], color[1], color[2]);
420+
419421
glBindTexture(GL_TEXTURE_2D, 0);
420422
glBegin(GL_QUADS);
421423
glVertex2d(startScreenPos.first - cosPerp * roadWidth, startScreenPos.second - sinPerp * roadWidth);
@@ -435,7 +437,9 @@ void DrawingGameVisitor::visit(Settlement& settlement) {
435437
auto centerScreenPos = coordToScreen(settlement.getLocation());
436438

437439
glBindTexture(GL_TEXTURE_2D, 0);
438-
glColor3d(0., 0., 0.);
440+
float* color = settlement.getOwner().getColor();
441+
glColor3d(color[0], color[1], color[2]);
442+
439443
glBegin(GL_QUADS);
440444
glVertex2d(centerScreenPos.first, centerScreenPos.second + settlementRadius);
441445
glVertex2d(centerScreenPos.first + settlementRadius, centerScreenPos.second);
@@ -454,7 +458,10 @@ void DrawingGameVisitor::visit(City& city) {
454458
auto centerScreenPos = coordToScreen(city.getLocation());
455459

456460
glBindTexture(GL_TEXTURE_2D, 0);
457-
glColor3d(0., 0., 0.);
461+
462+
float* color = city.getOwner().getColor();
463+
glColor3d(color[0], color[1], color[2]);
464+
458465
glBegin(GL_QUADS);
459466
glVertex2d(centerScreenPos.first + cityRadius, centerScreenPos.second + cityRadius);
460467
glVertex2d(centerScreenPos.first + cityRadius, centerScreenPos.second - cityRadius);
@@ -473,7 +480,10 @@ void DrawingGameVisitor::visit(Wonder& wonder) {
473480
auto centerScreenPos = coordToScreen(wonder.getLocation());
474481

475482
glBindTexture(GL_TEXTURE_2D, 0);
476-
glColor3d(0., 0., 0.);
483+
484+
float* color = wonder.getOwner().getColor();
485+
glColor3d(color[0], color[1], color[2]);
486+
477487
glBegin(GL_QUADS);
478488
glVertex2d(centerScreenPos.first + wonderRadius, centerScreenPos.second + wonderRadius);
479489
glVertex2d(centerScreenPos.first + wonderRadius, centerScreenPos.second - wonderRadius);

src/Player.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Player::Player(GameBoard& board, std::string playerName) : name(playerName), boa
4949
c = 0;
5050
}
5151

52+
color[0] = .01 * (float)(std::rand()%101);
53+
color[1] = .01 * (float)(std::rand()%101);
54+
color[2] = .01 * (float)(std::rand()%101);
55+
56+
color[std::rand()%3] = 0;
57+
5258
}
5359

5460
/**
@@ -84,6 +90,12 @@ Player::Player(GameBoard& board, XMLElement* elem) : board(board)
8490
longestRoad = 0;
8591
victoryPoints = 0;
8692
baseVictoryPoints = 0;
93+
94+
color[0] = .01 * (float)(std::rand()%101);
95+
color[1] = .01 * (float)(std::rand()%101);
96+
color[2] = .01 * (float)(std::rand()%101);
97+
98+
color[std::rand()%3] = 0;
8799
}
88100

89101
/**
@@ -93,6 +105,11 @@ Player::~Player() {
93105

94106
}
95107

108+
float* Player::getColor(){
109+
return color;
110+
}
111+
112+
96113
/**
97114
* The number of development cards the player is holding.
98115
* @return The number of cards.
@@ -507,10 +524,8 @@ bool Player::playRoadBuilding(Coordinate start1, Coordinate end1, Coordinate sta
507524
/**
508525
* A cheat class that gives the player 5 of every development card, meant for debugging
509526
*/
510-
void Player::giveDevCardBoon(){
511-
for(int i = 0; i < 5; i++){
512-
developmentCards[i]+=5;
513-
}
527+
void Player::setStartingValues(){
528+
developmentCards[ROADBUILDING] = 1;
514529
}
515530

516531

src/main.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,21 @@ int main(int argc, char *argv[]) {
7676

7777
updateViewport(windowWidth, windowHeight);
7878

79-
GameBoard model({"testPlayer", "testPlayer2", "testPlayer3", "testPlayer4"});
79+
GameBoard model({"Player1", "Player2", "Player3", "Player4"});
8080
GameView view(model);
8181
GameController controller(model, view);
8282

83-
Player& firstPlayer = model.getPlayer(0);
84-
85-
model.PlaceSettlement(Coordinate{0, 0}, firstPlayer);
86-
model.PlaceRoad(Coordinate{0, 0}, Coordinate{1, 0}, firstPlayer);
87-
model.PlaceRoad(Coordinate{1, 0}, Coordinate{1, 1}, firstPlayer);
88-
model.PlaceRoad(Coordinate{1, 1}, Coordinate{0, 2}, firstPlayer);
89-
model.PlaceSettlement(Coordinate{0, 2}, firstPlayer);
90-
model.UpgradeSettlement(Coordinate{0, 2});
83+
model.initializeGame();
9184

85+
// Player& firstPlayer = model.getPlayer(0);
86+
//
87+
// model.PlaceSettlement(Coordinate{0, 0}, firstPlayer);
88+
// model.PlaceRoad(Coordinate{0, 0}, Coordinate{1, 0}, firstPlayer);
89+
// model.PlaceRoad(Coordinate{1, 0}, Coordinate{1, 1}, firstPlayer);
90+
// model.PlaceRoad(Coordinate{1, 1}, Coordinate{0, 2}, firstPlayer);
91+
// model.PlaceSettlement(Coordinate{0, 2}, firstPlayer);
92+
// model.UpgradeSettlement(Coordinate{0, 2});
93+
//
9294
bool running = true;
9395
while(running) {
9496
SDL_Event event;

0 commit comments

Comments
 (0)