Begin implementation of stats
This commit is contained in:
parent
2d09187508
commit
3d72f4a7dd
@ -295,8 +295,9 @@ void stat_ui(WINDOW *win) {
|
|||||||
|
|
||||||
/* Main function. Creates main menu */
|
/* Main function. Creates main menu */
|
||||||
int main() {
|
int main() {
|
||||||
FILE *words_file;
|
FILE *words_file, *stats_file;
|
||||||
Word_array *word_array;
|
Word_array *word_array;
|
||||||
|
Stat_struct stats;
|
||||||
int cursor_x = 0, cursor_y = 0, run = 1;
|
int cursor_x = 0, cursor_y = 0, run = 1;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
@ -306,8 +307,9 @@ int main() {
|
|||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
noecho();
|
noecho();
|
||||||
|
|
||||||
words_file = fopen("words.txt", "r");
|
|
||||||
print_centered_text(stdscr, 4, "Loading...");
|
print_centered_text(stdscr, 4, "Loading...");
|
||||||
|
words_file = fopen("words.txt", "r");
|
||||||
|
stats_file = fopen("stats", "r");
|
||||||
|
|
||||||
if (has_colors() == FALSE) {
|
if (has_colors() == FALSE) {
|
||||||
print_centered_text(stdscr, 4, "Your terminal does not support color");
|
print_centered_text(stdscr, 4, "Your terminal does not support color");
|
||||||
@ -335,6 +337,18 @@ int main() {
|
|||||||
parse_words_file(words_file, word_array);
|
parse_words_file(words_file, word_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Creates a new stats file if one is not detected */
|
||||||
|
if (stats_file == NULL) {
|
||||||
|
stats_file = fopen("stats", "w");
|
||||||
|
create_stats_file(stats_file);
|
||||||
|
stats_file = fopen("stats", "r");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load stats from stats file */
|
||||||
|
/* These will be modified as the program runs and the stats file will be updated
|
||||||
|
upon program exit */
|
||||||
|
load_stats(stats_file, &stats);
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
while (run) {
|
while (run) {
|
||||||
@ -404,6 +418,9 @@ int main() {
|
|||||||
/* Exiting */
|
/* Exiting */
|
||||||
refresh();
|
refresh();
|
||||||
endwin();
|
endwin();
|
||||||
|
|
||||||
|
/* Saves stats and exits file */
|
||||||
|
save_stats(stats_file, &stats);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
30
utilities.c
30
utilities.c
@ -73,6 +73,36 @@ int parse_words_file(FILE *words_file, Word_array *words) {
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Creates empty stats file */
|
||||||
|
int create_stats_file(FILE *stats_file) {
|
||||||
|
/* Numerical Stats */
|
||||||
|
fputs("Best WPM: 0\n", stats_file);
|
||||||
|
fputs("10w: 0\n", stats_file);
|
||||||
|
fputs("25w: 0\n", stats_file);
|
||||||
|
fputs("50w: 0\n", stats_file);
|
||||||
|
fputs("100w: 0\n", stats_file);
|
||||||
|
fputs("Tests completed: 0\n", stats_file);
|
||||||
|
|
||||||
|
/* Dynamic Stats (Used for calculating average WPM, Accuracy, etc) */
|
||||||
|
fputs("Characters typed: 0\n", stats_file);
|
||||||
|
fputs("Characters correct: 0\n", stats_file);
|
||||||
|
fputs("Time typed: 0\n", stats_file);
|
||||||
|
fclose(stats_file);
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int load_stats(FILE *stats_file, Stat_struct *stats) {
|
||||||
|
/* Placeholder */
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_stats(FILE *stats_file, Stat_struct *stats) {
|
||||||
|
/* Placeholder */
|
||||||
|
|
||||||
|
fclose(stats_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Appends first parameter to the end of end of the second parameter
|
/* Appends first parameter to the end of end of the second parameter
|
||||||
(Does not change size of the target, assumes there is space) */
|
(Does not change size of the target, assumes there is space) */
|
||||||
void append_line(char *source, char *target) {
|
void append_line(char *source, char *target) {
|
||||||
|
@ -25,7 +25,16 @@ typedef struct {
|
|||||||
Word *words;
|
Word *words;
|
||||||
} Word_array;
|
} Word_array;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int best_wpm, w_10, w_25, w_50, w_100;
|
||||||
|
int tests_complete, chars_typed, chars_correct;
|
||||||
|
double time_typed; /* In seconds */
|
||||||
|
} Stat_struct;
|
||||||
|
|
||||||
void clear_word_array(Word_array *array);
|
void clear_word_array(Word_array *array);
|
||||||
int generate_words(int num_words, Word_array *words, Word_array *to_return);
|
int generate_words(int num_words, Word_array *words, Word_array *to_return);
|
||||||
int parse_words_file(FILE *words_file, Word_array *words);
|
int parse_words_file(FILE *words_file, Word_array *words);
|
||||||
|
int create_stats_file(FILE *stats_file);
|
||||||
|
int load_stats(FILE *stats_file, Stat_struct *stats);
|
||||||
|
int save_stats(FILE *stats_file, Stat_struct *stats);
|
||||||
void append_line(char *source, char *target);
|
void append_line(char *source, char *target);
|
Loading…
x
Reference in New Issue
Block a user