-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.c
86 lines (71 loc) · 2.33 KB
/
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
#include "menu.h"
int game_menu(int resume_state)
{
int i = 0, highlighted_option = 0, pressed_key = 0;
char menu_options[4][20] = {0};
int number_of_rows = 0, number_of_columns = 0;
// Scriem optiunile pentru meniu
strcat(menu_options[0], "New Game");
strcat(menu_options[1], "Resume Game");
strcat(menu_options[2], "Quit");
// Salvam numarul de randuri si de coloane al ecranului
getmaxyx(stdscr, number_of_rows, number_of_columns);
// Prima optiune evidentiata este primul cuvant din meniu
highlighted_option=0;
pressed_key=0;
while (FOREVER) {
for (i = 0; i < 3; i ++) {
if (i == highlighted_option) {
attron(A_REVERSE);
}
mvprintw(i + number_of_rows/3, (number_of_columns / 2) - (strlen(menu_options[i]) / 2), menu_options[i]);
attroff(A_REVERSE);
mvprintw(number_of_rows / 3 - 2, (number_of_columns / 2) - (strlen("HANGMAN") / 2), "HANGMAN");
}
pressed_key = getch();
clear();
switch (pressed_key) {
case KEY_UP:
{
highlighted_option --;
if (highlighted_option == -1) {
highlighted_option = 2;
}
break;
}
case KEY_DOWN:
{
highlighted_option++;
if (highlighted_option == 3) {
highlighted_option = 0;
}
break;
}
default:
break;
}
if (pressed_key == 10 && highlighted_option != 1) {
break;
}
if (pressed_key == 10 && highlighted_option == 1 && resume_state == 1) {
break;
}
if (pressed_key == 10 && highlighted_option == 1 && resume_state == 0) {
mvprintw(number_of_rows / 3 + 4, (number_of_columns / 2) - (strlen("You don't have a game to resume, start a game first!") / 2),
"You don't have a game to resume, start a game first!");
}
}
if (highlighted_option == 0) {
clear();
return 2;
}
if (highlighted_option == 1) {
clear();
return 1;
}
if (highlighted_option == 2) {
endwin();
return 0;
}
return 0;
}