-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (58 loc) · 1.13 KB
/
main.cpp
File metadata and controls
70 lines (58 loc) · 1.13 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
#include "anscii.h"
#include "ttyspeed.h"
#include "word_generator.h"
#include <csignal>
#include <cstdio>
#include <string.h>
int main() {
ttySpeed t;
int time = 5;
WordGenerator wg;
std::string random_text = wg.get_text(50);
t.raw(0);
t.box(1);
t.cursor(true);
t.draw_footer();
t.time_border();
printf("\x1b[2;2H");
printf("Time: %d", time);
t.printText(random_text, 1, 3);
char x[3] = {0};
while (t.countdown) {
read(0, &x, 3);
if (x[0] == 0) {
if (!t.timer_started) {
printf("\x1b[2;2H");
printf("Time: %02d", time);
fflush(stdout);
t.mv_xy(t.cursor_x(), t.cursor_y());
continue;
}
t.print_time(time);
continue;
}
if (x[0] == 27 && x[1] == 0) {
t.normal();
exit(0);
}
fflush(stdout);
t.check(x[0]);
t.print_time(time);
if (t.is_finished()) {
t.countdown = 0;
break;
}
memset(x, 0, 3);
}
t.display_result();
while (true) {
read(0, &x, 3);
if (x[0] == 0)
continue;
if (x[0] == 27 || x[0] == 'q') {
t.normal();
exit(0);
}
}
return 0;
}