-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_menu.c
98 lines (77 loc) · 2.16 KB
/
main_menu.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
85
86
87
88
89
90
91
92
93
94
95
#include <string.h>
#include <ncurses.h>
#ifndef __MAGIC__
#define __MAGIC__
#include "magic_numbers.h"
#endif
#ifndef __COLOR__
#define __COLOR__
#include "color_pairs.h"
#endif
#ifndef __DRAW__
#define __DRAW__
#include "draw.h"
#endif
#ifndef __MENU__
#define __MENU__
#include "menu.h"
#endif
void menu(int* GAMESTATE, WINDOW** options, WINDOW* background, WINDOW* title)
{
checkScreenSize();
int selection = 0;
int keyPRESS;
char option_text[3][20] = {"New Game", "Resume", "Exit"};
draw_background(background);
draw_title(title);
draw_buttons(options);
//print all options in their boxes
int i;
for(i = 0; i < OPTION_COUNT; i++)
{
mvwprintw(options[i], 1, 20/2 - strlen(option_text[i])/2, option_text[i]);
wrefresh(options[i]);
}
//according to keypresses highlight an option
while(*GAMESTATE)
{
mvwprintw(options[selection], 1, 20/2 - strlen(option_text[selection])/2, option_text[selection]);
wrefresh(options[selection]);
switch(keyPRESS)
{
case KEY_UP:
selection--;
if(selection < 0)
selection = 0;
break;
case KEY_DOWN:
selection++;
if(selection == OPTION_COUNT)
selection = OPTION_COUNT - 1;
break;
}
if(keyPRESS == 10)
{
switch (selection)
{
case 0:
*GAMESTATE = 2;
break;
case 1:
*GAMESTATE = 3;
break;
case 2:
*GAMESTATE = 0;
break;
}
draw_background(background);
break;
}
//highlight the currently selected option and print it
wattron(options[selection], COLOR_PAIR(SELECTED_TEXT));
mvwprintw(options[selection], 1, 20/2 - strlen(option_text[selection])/2, option_text[selection]);
wattroff(options[selection], COLOR_PAIR(SELECTED_TEXT));
wrefresh(options[selection]);
keyPRESS = getch();
}
}