-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
84 lines (69 loc) · 1.76 KB
/
main.c
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
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
#include "windows.h"
#include "lib/questions.h"
#include "lib/utility.h"
#include "lib/db.h"
#include "src/game.h"
const int num_questions = 5; // Number of questions to ask
int asked[QUESTION_COUNT] = {}; // To keep track of asked questions
int is_new_player = 0; // To check if the player is new or not
char name[100] = "";
struct Player player;
void welcome_screen() {
show_title();
welcome_message(num_questions);
get_name(name);
}
void game_screen() {
clear_screen();
show_title();
int score = play(num_questions, asked);
if (score > player.best_score) {
player.best_score = score;
}
printf("Quiz completed! Your score is: %d\n", score);
}
int main() {
clear_screen();
srand(time(NULL));
// Customize Console
SetConsoleCP(15);
SetConsoleTitle("Brain Buster");
// === welcome Screen ===
welcome_screen();
player = load_player_record(name);
if (player.name[0] == '\0') {
strcpy(player.name, name);
player.best_score = 0;
is_new_player = 1;
}
else {
is_new_player = 0;
}
while (1) {
clear_screen();
show_title();
if (is_new_player) {
printf("Welcome %s!\n", name);
}
else {
printf("Welcome back %s!\nYour best score is: %d\n", name, player.best_score);
}
int menu_choice = menu(name);
// Play Game
if (menu_choice == 1) {
// === Game Screen ===
game_screen();
save_player_record(player);
}
// Exit
else if (menu_choice == 2) {
save_player_record(player);
break;
}
};
return 0;
}