-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
152 lines (109 loc) · 3.19 KB
/
utils.h
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
#ifndef WPMC_UTILS_H
#define WPMC_UTILS_H
#include <ncurses.h>
#include "buffer.h"
//TODO: streamline input
//TODO: allow custom imputs
//TODO: Add option to repeat at the end of the game
//TODO: multiple texts etc...
typedef struct Game_Status_t
{
int status; // -1 end, 0 ready, 1 just started (first iter), 2 ongoing
int input; //latest user input
char *text; //beginning of text
char *text_ptr; //start of current word
Text_Buff *buffer; // buffer for storing user input
size_t index; //index of the correct entry
size_t start; //start of thw current word
size_t err_char; //number of error characters
size_t text_len; //total length of the text
} Game_Status;
typedef struct Statsistics_t
{
double start_t;
double end_t;
double cps_raw;
double wpm_raw;
double cps;
double wpm;
double err;
int raw_ch;
int ch;
} Stats;
typedef struct Title_Window_t
{
WINDOW *window;
} Title_Win;
typedef struct Text_Window_t
{
WINDOW *window; // curses window
char *content; // content of the window
char *frame_start_ptr; // start of the frame
size_t frame_size; // size of the fame
size_t correct; // number of green chars
size_t correct_lines; // number of lines to be highlighted green
size_t correct_tail; // remainig green chars
size_t incorrect; // number of red chars
size_t incorrect_lines; // number of chars to be highlighted red
size_t incorrect_head; // number of leading red chars
size_t incorrect_tail; // number of trailing red chars
size_t start_x; //position in window of text
size_t start_y;
} Text_Win;
typedef struct User_Window_t
{
WINDOW *window;
char *buffer;
} User_Win;
typedef struct Prompt_Window_t
{
WINDOW *window;
} Prompt_Win;
#ifdef DEBUG
typedef struct Debug_Window_t
{
WINDOW *window;
Game_Status *status;
Stats *statistics;
Text_Buff *user_buff;
} Debug_Win;
#endif
typedef struct Statistics_Window_t
{
WINDOW *window;
int hide;
Stats *statistics;
} Stat_Win;
typedef struct Game_Window_t
{
Title_Win *title;
Text_Win *text;
Prompt_Win *prompt;
User_Win *user;
Stat_Win *stats;
#ifdef DEBUG
Debug_Win *debug;
#endif
} Game_Win;
void get_input_from_file(char **text, char *name);
void get_random_text(char **text, size_t num);
void get_default_text(char **text);
int pre_start_state_config(Game_Status *status, Stats *measures, char *text);
int display_status_connect(Game_Win *game_window, Game_Status *status, Stats *measures);
int get_user_input(Game_Win *game_window, Game_Status *status);
int start_game(Game_Status *status, Stats *measures);
int end_of_game(Game_Status *status, Stats *measures);
int start_measurement(Stats *stats);
int end_measurement(Stats *stats);
int compute_stats(Stats *stats);
int update_game_display(Game_Win *game_window, Game_Status *status);
int update_game_state(Game_Status *status, Stats *measures);
int init_display_updates();
Game_Win *create_game_win();
Game_Status *create_game_status();
Stats *create_stats();
int delete_stats(Stats *stats);
int delete_game_status(Game_Status *status);
int delete_game_win(Game_Win *game_win);
void free_text(char *text);
#endif