forked from hwauck/statue-puzzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributeBox.cc
executable file
·98 lines (83 loc) · 3.36 KB
/
attributeBox.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "attributeBox.h"
#include <vector>
#include "ccc_win.h"
#include <iostream>
AttributeBox::AttributeBox(Player* player, double mapWidth, double mapHeight, std::string color, Point llcorner) {
this->BOX_WIDTH = mapWidth;
this->BOX_HEIGHT = 0.1 * mapHeight;
this->title = player->getName();
this->categories.push_back(player->getScoreCategory());
this->categories.push_back(player->getHealthCategory());
this->categories.push_back(player->getGoldCategory());
this->NUM_STATS = categories.size();
this->TEXT_BOX_WIDTH = 1 / (3.0 * NUM_STATS + 1) * BOX_WIDTH;
this->TEXT_BOX_HEIGHT = 0.15 * BOX_HEIGHT;
this->color = color;
this->llcorner = llcorner;
this->player = player;
createTitle();
calculateTextBoxPositions();
}
void AttributeBox::createTitle() {
int titleLength = title.size();
const double TITLE_X_POS = BOX_WIDTH / 2 - titleLength / 4;
const double TITLE_Y_POS = SCREEN_HEIGHT;
titlePos = Point(TITLE_X_POS, TITLE_Y_POS);
}
void AttributeBox::calculateTextBoxPositions() {
const double X_OFFSET = 1 / (8.0 * NUM_STATS) * BOX_WIDTH;
const double Y_OFFSET = 0.5 * BOX_HEIGHT;
const double BOX_Y_OFFSET = 0.75;
//for first box only
int numChars = categories[0].getName().size();
Point textPos(llcorner.get_x() + X_OFFSET, llcorner.get_y() + Y_OFFSET);
textBoxTextPositions.push_back(textPos);
Point boxPos(textPos.get_x() + numChars * CHAR_WIDTH, textPos.get_y() - BOX_Y_OFFSET);
textBoxPositions.push_back(boxPos);
double currentX = boxPos.get_x() + TEXT_BOX_WIDTH;
for(int i = 1; i < NUM_STATS; i++) {
numChars = categories[i].getName().size();
Point textPos(currentX + X_OFFSET, llcorner.get_y() + Y_OFFSET);
textBoxTextPositions.push_back(textPos);
Point boxPos(textPos.get_x() + numChars * CHAR_WIDTH, textPos.get_y() - BOX_Y_OFFSET);
textBoxPositions.push_back(boxPos);
currentX = boxPos.get_x() + TEXT_BOX_WIDTH;
}
}
void AttributeBox::draw() {
//draws overall box structure
drawSolidRectangle(BOX_WIDTH, BOX_HEIGHT, llcorner, WIDTH_INCREMENT, color);
//draws player's name
cwin << Message(titlePos, title);
//draws text boxes and their text
for(int unsigned i = 0; i < textBoxPositions.size(); i++) {
drawSolidRectangle(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT, textBoxPositions[i], WIDTH_INCREMENT, "white");
cwin << Message(textBoxTextPositions[i], categories[i].getName());
Point quantityPos(textBoxPositions[i].get_x(), textBoxPositions[i].get_y() + CHAR_OFFSET);
cwin << Message(quantityPos, categories[i].getQuantity());
}
}
void AttributeBox::updateQuantities() {
this->categories[0].setQuantity(player->getScore());
this->categories[1].setQuantity(player->getHealth());
this->categories[2].setQuantity(player->getGold());
for(int unsigned i = 0; i < textBoxPositions.size(); i++) {
drawSolidRectangle(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT, textBoxPositions[i], WIDTH_INCREMENT, "white");
cwin << Message(textBoxTextPositions[i], categories[i].getName());
Point quantityPos(textBoxPositions[i].get_x(), textBoxPositions[i].get_y() + CHAR_OFFSET);
cwin << Message(quantityPos, categories[i].getQuantity());
}
}
//void test() {
// //test AttributeBox
// Category gold("Gold", 100);
// Category crystal("Crystal", 50);
// Category score("Score", 0);
// Category blah("blah", 0);
//
// Player player1("Helen", 100, 50);
// Point p(0,0);
// AttributeBox playerStats(player1, 30.0, 30.0, "red", p);
// cwin.coord(0,30,30,0);
// playerStats.draw();
//}