-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.c
82 lines (63 loc) · 1.54 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
#include <stdio.h>
#include <stdbool.h>
#include "lib/keyboard.h"
#include "lib/types.h"
#include "lib/screen.h"
#include "src/game.h"
#include "src/menu.h"
int main() {
Cursor cursor = {.x=0, .y=0, .pointer='>'};
Program program = {.running=true};
Screen status_old_screen = get_screen_size();
int menu_option = 0;
init_keyboard();
no_cursor();
clear();
draw_menu(&cursor, &menu_option);
do {
Screen status_new_screen = get_screen_size();
if(diff_screen(&status_old_screen, &status_new_screen)) {
status_old_screen = status_new_screen;
clear();
draw_menu(&cursor, &menu_option);
}
if(kbhit()) {
int key = readch();
if(key == CTRL_C)
break;
if(key == KEY_ARROW_UP) cursor.y--;
if(key == KEY_ARROW_DOWN) cursor.y++;
if(key == KEY_ENTER) {
switch(menu_option){
case MENU_CONTINUE: {
game();
break;
}
case MENU_NEW_GAME: {
remove_save_state(SAVE_STATE_PATH);
game();
break;
}
case MENU_HOW_TO_PLAY: {
how_to_play();
break;
}
case MENU_EXIT: {
program.running = false;
break;
}
}
}
draw_menu(&cursor, &menu_option);
}
goto_xy(cursor.x, cursor.y);
text_color(IRED);
printf("%c", cursor.pointer);
reset_video();
}
while(program.running);
close_keyboard();
show_cursor();
clear();
return 0;
}