save record
This commit is contained in:
parent
19a8890509
commit
d81864bee0
36
main.c
36
main.c
|
@ -69,11 +69,9 @@ const Color hover_color = RED;
|
||||||
|
|
||||||
float timer = 0.0f;
|
float timer = 0.0f;
|
||||||
char timer_text[10] = {0};
|
char timer_text[10] = {0};
|
||||||
char timer_record[GAME_TYPE_NB][10] = {
|
char timer_record[GAME_TYPE_NB][10] = {"9999", "9999", "9999"};
|
||||||
[BEGINNER] = "12",
|
FILE *record_file_read;
|
||||||
[INTERMEDIATE] = "42",
|
FILE *record_file_write;
|
||||||
[EXPERT] = "69"
|
|
||||||
};
|
|
||||||
int need_to_fill = 1;
|
int need_to_fill = 1;
|
||||||
|
|
||||||
#define INIT_TEXTURE(img, tex) \
|
#define INIT_TEXTURE(img, tex) \
|
||||||
|
@ -279,10 +277,35 @@ void switch_mode(GameType gt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_record(void)
|
||||||
|
{
|
||||||
|
for (
|
||||||
|
int i=0;
|
||||||
|
i<GAME_TYPE_NB &&
|
||||||
|
fgets(timer_record[i], sizeof(timer_record[i]), record_file_read);
|
||||||
|
i++
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void save_record(void)
|
||||||
|
{
|
||||||
|
record_file_write = fopen(RECORD_FILE, "w");
|
||||||
|
|
||||||
|
fprintf(record_file_write, "%s\n%s\n%s\n",
|
||||||
|
timer_record[BEGINNER],
|
||||||
|
timer_record[INTERMEDIATE],
|
||||||
|
timer_record[EXPERT]);
|
||||||
|
|
||||||
|
fclose(record_file_write);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
|
record_file_read = fopen(RECORD_FILE, "r");
|
||||||
|
load_record();
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
#ifdef RELEASE
|
#ifdef RELEASE
|
||||||
SetTraceLogLevel(LOG_ERROR);
|
SetTraceLogLevel(LOG_ERROR);
|
||||||
|
@ -519,7 +542,8 @@ int main(void)
|
||||||
if (game_state != LOSE && count_undiscovered_cell <= nb_bomb) {
|
if (game_state != LOSE && count_undiscovered_cell <= nb_bomb) {
|
||||||
if (timer < atoi(timer_record[current_game_type])) {
|
if (timer < atoi(timer_record[current_game_type])) {
|
||||||
game_state = RECORD;
|
game_state = RECORD;
|
||||||
snprintf(timer_record[current_game_type], GAME_TYPE_NB, "%d", (int) timer);
|
snprintf(timer_record[current_game_type], sizeof(timer_record[0]), "%d", (int) timer);
|
||||||
|
save_record();
|
||||||
} else {
|
} else {
|
||||||
game_state = WIN;
|
game_state = WIN;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue