-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreBoard.cpp
More file actions
194 lines (171 loc) · 6.45 KB
/
Copy pathScoreBoard.cpp
File metadata and controls
194 lines (171 loc) · 6.45 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "ScoreBoard.h"
void ScoreBoard::initVariables(unsigned short totalPlayers, std::vector<Player*> players, Bank* bank, int player_turn, sf::Font& font)
{
this->font= font;
this->total_players = totalPlayers;
this->playerptr = players;
this->bank = bank;
this->player_turn = player_turn;
}
void ScoreBoard::initTextboxes()
{
if (total_players == 2) {
this->textScore["PLAYER1"] = new Textbox(1415, 206, 100, 30, 20,
&this->font, std::to_string(this->playerptr[0]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER2"] = new Textbox(1415, 246, 100, 30, 20,
&this->font, std::to_string(this->playerptr[1]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER3"] = new Textbox(1415, 286, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER4"] = new Textbox(1415, 326, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200));
}
else if (total_players == 3) {
this->textScore["PLAYER1"] = new Textbox(1415, 206, 100, 30, 20,
&this->font, std::to_string(this->playerptr[0]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER2"] = new Textbox(1415, 246, 100, 30, 20,
&this->font, std::to_string(this->playerptr[1]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER3"] = new Textbox(1415, 286, 100, 30, 20,
&this->font, std::to_string(this->playerptr[2]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER4"] = new Textbox(1415, 326, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200));
}
else if (total_players == 4) {
this->textScore["PLAYER1"] = new Textbox(1415, 206, 100, 30, 20,
&this->font, std::to_string(this->playerptr[0]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER2"] = new Textbox(1415, 246, 100, 30, 20,
&this->font, std::to_string(this->playerptr[1]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER3"] = new Textbox(1415, 286, 100, 30, 20,
&this->font, std::to_string(this->playerptr[2]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["PLAYER4"] = new Textbox(1415, 326, 100, 30, 20,
&this->font, std::to_string(this->playerptr[3]->getMoneyAmount()),
sf::Color(70, 70, 70, 200));
}
this->textScore["BANK"] = new Textbox(1418, 164, 100, 30, 20,
&this->font, std::to_string(this->bank->getAmount()),
sf::Color(70, 70, 70, 200));
this->textScore["SPACE_NAME"] = new Textbox(1220, 450, 100, 40, 20,
&this->font, "START",
sf::Color(70, 70, 70, 200));
this->textScore["SPACE_OWNER"] = new Textbox(1220, 500, 100, 40, 20,
&this->font, "Space owner: x",
sf::Color(70, 70, 70, 200));
}
void ScoreBoard::initMoneyBalanceTextboxes()
{
this->textScoreBalance["PLAYER1"] = new MoneyBalanceTextbox(1315, 206, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200)), sf::Color::Green;
this->textScoreBalance["PLAYER2"] = new MoneyBalanceTextbox(1315, 246, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200)), sf::Color::Green;
this->textScoreBalance["PLAYER3"] = new MoneyBalanceTextbox(1315, 286, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200)), sf::Color::Green;
this->textScoreBalance["PLAYER4"] = new MoneyBalanceTextbox(1315, 326, 100, 30, 20,
&this->font, std::to_string(0),
sf::Color(70, 70, 70, 200)), sf::Color::Green;
}
ScoreBoard::ScoreBoard(unsigned short totalPlayers, std::vector<Player*> players, Bank* bank, int player_turn, sf::Font& font)
{
this->initVariables(totalPlayers, players, bank, player_turn, font);
this->initTextboxes();
this->initMoneyBalanceTextboxes();
this->circlePointers = new CirclePointers(this->total_players);
}
ScoreBoard::~ScoreBoard()
{
for (auto& text : this->textScore)
delete text.second;
this->textScore.clear();
for (auto& text : this->textScoreBalance)
delete text.second;
this->textScoreBalance.clear();
}
//Functions
void ScoreBoard::updateAmountDisp()
{
if (this->player_turn == 0)
textScore["PLAYER1"]->setText(std::to_string(this->playerptr[this->player_turn]->getMoneyAmount()));
else if (this->player_turn == 1)
textScore["PLAYER2"]->setText(std::to_string(this->playerptr[this->player_turn]->getMoneyAmount()));
else if (this->player_turn == 2)
textScore["PLAYER3"]->setText(std::to_string(this->playerptr[this->player_turn]->getMoneyAmount()));
else if (this->player_turn == 3)
textScore["PLAYER4"]->setText(std::to_string(this->playerptr[this->player_turn]->getMoneyAmount()));
textScore["BANK"]->setText(std::to_string(this->bank->getAmount()));
}
void ScoreBoard::updateNames(std::string space_name, short space_owner)
{
textScore["SPACE_NAME"]->setText(space_name);
textScore["SPACE_OWNER"]->setText("Space owner: " + std::to_string(space_owner + 1));
}
void ScoreBoard::update(const float& dt, int player_turn, std::string space_name, short space_owner)
{
this->player_turn = player_turn;
this->updateAmountDisp();
this->updateNames(space_name, space_owner);
circlePointers->update(player_turn);
}
void ScoreBoard::renderTextScore(sf::RenderTarget* target)
{
for (auto& it : this->textScore)
{
it.second->render(target);
}
}
void ScoreBoard::renderTextBalance(sf::RenderTarget* target)
{
for (auto& it : this->textScoreBalance)
{
if(it.second->isHidden() == 0)
it.second->render(target);
}
}
void ScoreBoard::render(sf::RenderTarget* target)
{
this->renderTextScore(target);
this->renderTextBalance(target);
this->circlePointers->render(target);
}
void ScoreBoard::changeScoreBalance(int playerNum, int ammount, bool hidden)
{
switch (playerNum)
{
case 0:
this->textScoreBalance["PLAYER1"]->setHidden(hidden);
this->textScoreBalance["PLAYER1"]->setBalance(ammount);
break;
case 1:
this->textScoreBalance["PLAYER2"]->setHidden(hidden);
this->textScoreBalance["PLAYER2"]->setBalance(ammount);
break;
case 2:
this->textScoreBalance["PLAYER3"]->setHidden(hidden);
this->textScoreBalance["PLAYER3"]->setBalance(ammount);
break;
case 3:
this->textScoreBalance["PLAYER4"]->setHidden(hidden);
this->textScoreBalance["PLAYER4"]->setBalance(ammount);
break;
default:
break;
}
}
void ScoreBoard::resetMoneyBalanceTextboxes()
{
for (int i = 0; i<4; i++)
{
changeScoreBalance(i, 0, true);
}
}