Skip to content

Commit 4194963

Browse files
committed
Merge pull request #40 from Databean/colorTuple
Changed player color to a tuple
2 parents 894803d + 70cc358 commit 4194963

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

include/Player.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Player {
4848
int resources[5];
4949
int tradeModifiers[5];
5050

51-
float color[3];
51+
std::tuple<float, float, float> color;
5252

5353

5454
void tradeWithBank(std::array<int, 5> offer, std::array<int, 5> demand);
@@ -71,7 +71,7 @@ class Player {
7171
void setLongestRoad(bool);
7272
void setLongestRoadSize(int);
7373

74-
float* getColor();
74+
std::tuple<float, float, float> getColor();
7575

7676
int getVictoryPointsWithoutCards();
7777
int getVictoryPointCards();

src/GameView.cpp

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

418-
float* color = road.getOwner().getColor();
419-
glColor3d(color[0], color[1], color[2]);
418+
auto color = road.getOwner().getColor();
419+
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
420420

421421
glBindTexture(GL_TEXTURE_2D, 0);
422422
glBegin(GL_QUADS);
@@ -437,8 +437,8 @@ void DrawingGameVisitor::visit(Settlement& settlement) {
437437
auto centerScreenPos = coordToScreen(settlement.getLocation());
438438

439439
glBindTexture(GL_TEXTURE_2D, 0);
440-
float* color = settlement.getOwner().getColor();
441-
glColor3d(color[0], color[1], color[2]);
440+
auto color = settlement.getOwner().getColor();
441+
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
442442

443443
glBegin(GL_QUADS);
444444
glVertex2d(centerScreenPos.first, centerScreenPos.second + settlementRadius);
@@ -459,8 +459,8 @@ void DrawingGameVisitor::visit(City& city) {
459459

460460
glBindTexture(GL_TEXTURE_2D, 0);
461461

462-
float* color = city.getOwner().getColor();
463-
glColor3d(color[0], color[1], color[2]);
462+
auto color = city.getOwner().getColor();
463+
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
464464

465465
glBegin(GL_QUADS);
466466
glVertex2d(centerScreenPos.first + cityRadius, centerScreenPos.second + cityRadius);
@@ -481,8 +481,8 @@ void DrawingGameVisitor::visit(Wonder& wonder) {
481481

482482
glBindTexture(GL_TEXTURE_2D, 0);
483483

484-
float* color = wonder.getOwner().getColor();
485-
glColor3d(color[0], color[1], color[2]);
484+
auto color = wonder.getOwner().getColor();
485+
glColor3f(std::get<0>(color), std::get<1>(color), std::get<2>(color));
486486

487487
glBegin(GL_QUADS);
488488
glVertex2d(centerScreenPos.first + wonderRadius, centerScreenPos.second + wonderRadius);

src/Player.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ 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;
52+
std::get<0>(color) = .01 * (float)(std::rand()%101);
53+
std::get<1>(color) = .01 * (float)(std::rand()%101);
54+
std::get<2>(color) = .01 * (float)(std::rand()%101);
55+
56+
int zeroChannel = std::rand()%3;
57+
if(zeroChannel == 0) { std::get<0>(color) = 0; }
58+
if(zeroChannel == 1) { std::get<1>(color) = 0; }
59+
if(zeroChannel == 2) { std::get<2>(color) = 0; }
5760

5861
}
5962

@@ -91,11 +94,14 @@ Player::Player(GameBoard& board, XMLElement* elem) : board(board)
9194
victoryPoints = 0;
9295
baseVictoryPoints = 0;
9396

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;
97+
std::get<0>(color) = .01 * (float)(std::rand()%101);
98+
std::get<1>(color) = .01 * (float)(std::rand()%101);
99+
std::get<2>(color) = .01 * (float)(std::rand()%101);
100+
101+
int zeroChannel = std::rand()%3;
102+
if(zeroChannel == 0) { std::get<0>(color) = 0; }
103+
if(zeroChannel == 1) { std::get<1>(color) = 0; }
104+
if(zeroChannel == 2) { std::get<2>(color) = 0; }
99105
}
100106

101107
/**
@@ -105,7 +111,7 @@ Player::~Player() {
105111

106112
}
107113

108-
float* Player::getColor(){
114+
std::tuple<float, float, float> Player::getColor(){
109115
return color;
110116
}
111117

0 commit comments

Comments
 (0)