-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreboard.cpp
More file actions
46 lines (40 loc) · 948 Bytes
/
Scoreboard.cpp
File metadata and controls
46 lines (40 loc) · 948 Bytes
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
#include "Scoreboard.hpp"
Scoreboard::Scoreboard(GameWindow* gw)
: game_window(gw),
score1(0), score2(0),
x1(gw->width / 2 - gw->width / 10),
x2(gw->width / 2 + gw->width / 10),
y1(gw->height / 15),
y2(gw->height / 15),
font_size(gw->height / 8)
{
update1();
update2();
}
void Scoreboard::reset()
{
score1 = score2 = 0;
}
void Scoreboard::update1()
{
score1_string = std::make_shared<Text>(game_window, std::to_string(score1), x1, y1, font_size);
}
void Scoreboard::update2()
{
score2_string = std::make_shared<Text>(game_window, std::to_string(score2), x2, y2, font_size);
}
void Scoreboard::render() const
{
score1_string->render();
score2_string->render();
SDL_RenderPresent(game_window->renderer);
}
int& Scoreboard::operator[](const int& index)
{
if (index == 0)
return score1;
else if (index == 1)
return score2;
else
throw Error("Wrong index called in Scoreboard operator[]"); // std::range_error
}