-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.cpp
More file actions
59 lines (52 loc) · 2.2 KB
/
Copy pathCounter.cpp
File metadata and controls
59 lines (52 loc) · 2.2 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
#include "Counter.h"
Counter::Counter() {
font.loadFromFile("src/Fonts/font.ttf");
white_clock_text.setFont(font);
white_clock_text.setCharacterSize(30);
black_clock_text.setFont(font);
black_clock_text.setCharacterSize(30);
}
void Counter::count_white_time(Board& board) {
white_clock_text.setPosition(1280 / 2 + 340 - white_clock_text.getLocalBounds().width / 2, 650);
if (board.white_plays) {
if (update_clock.getElapsedTime().asSeconds() >= 1 && white_time >= 0) {
white_time = white_time - 1;
update_clock.restart();
}
else if (white_time < 0) {
white_time = 0;
}
}
if (white_time / 60 >= 10 && white_time % 60 >= 10)
white_clock_text.setString(to_string(white_time / 60) + ":" + to_string(white_time % 60));
else if (white_time / 60 >= 10 && white_time % 60 < 10)
white_clock_text.setString(to_string(white_time / 60) + ":0" + to_string(white_time % 60));
else if (white_time / 60 < 10 && white_time % 60 >= 10)
white_clock_text.setString("0" + to_string(white_time / 60) + ":" + to_string(white_time % 60));
else
white_clock_text.setString("0" + to_string(white_time / 60) + ":0" + to_string(white_time % 60));
}
void Counter::count_black_time(Board& board) {
black_clock_text.setPosition(1280 / 2 + 340 - black_clock_text.getLocalBounds().width / 2, 30);
if (!board.white_plays) {
if (update_clock.getElapsedTime().asSeconds() >= 1 && black_time >= 0) {
black_time = black_time - 1;
update_clock.restart();
}
else if (black_time < 0) {
black_time = 0;
}
}
if (black_time / 60 >= 10 && black_time % 60 >= 10)
black_clock_text.setString(to_string(black_time / 60) + ":" + to_string(black_time % 60));
else if (black_time / 60 >= 10 && black_time % 60 < 10)
black_clock_text.setString(to_string(black_time / 60) + ":0" + to_string(black_time % 60));
else if (black_time / 60 < 10 && black_time % 60 >= 10)
black_clock_text.setString("0" + to_string(black_time / 60) + ":" + to_string(black_time % 60));
else
black_clock_text.setString("0" + to_string(black_time / 60) + ":0" + to_string(black_time % 60));
}
void Counter::draw(RenderWindow& window) {
window.draw(white_clock_text);
window.draw(black_clock_text);
}