Sistemate le chiamate al menu

This commit is contained in:
Carlo 2025-11-10 19:22:43 +01:00
parent 5de7f55889
commit 94fd8c9aec
10 changed files with 32 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -20,10 +20,13 @@ enum {
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
//extern char* choices[]; //extern char* choices[];
#define START_MODE 0
#define GMOVR_MODE 1
#define PAUSE_MODE 2
/* initialization and screens */ /* initialization and screens */
void init_colors(void); void init_colors(void);
int print_menu(WINDOW* win); int print_menu(WINDOW* win, int mode);
void print_gameover(WINDOW* win); void print_gameover(WINDOW* win);
void print_win_screen(WINDOW* win); void print_win_screen(WINDOW* win);

View file

@ -16,7 +16,7 @@
int game_run(void) { int game_run(void) {
WINDOW *game_window = NULL; WINDOW *game_window = NULL;
int height, width, win_startx, win_starty; int height, width, win_startx, win_starty;
char *pause_msg = "PAUSA: premi q per uscire dal gioco..."; char *pause_msg = "PAUSE...";
int pause = 0; int pause = 0;
int auto_shoot = 0; int auto_shoot = 0;

View file

@ -3,12 +3,6 @@
/************** FUNZIONI GUI ***************/ /************** FUNZIONI GUI ***************/
static char *choices[] = {
"Start Game",
"Exit",
NULL,
};
char* title[] = char* title[] =
{ {
"###########################################################################################################", "###########################################################################################################",
@ -52,8 +46,19 @@ void init_colors() {
init_pair(WINSC_PAIR, COLOR_YELLOW, COLOR_BLACK); init_pair(WINSC_PAIR, COLOR_YELLOW, COLOR_BLACK);
} }
static char *choices[] = {
"",
"Exit",
NULL,
};
// FUNCTION THAT PRINTS THE MENU // FUNCTION THAT PRINTS THE MENU
int print_menu(WINDOW* win) { int print_menu(WINDOW* win, int mode) {
switch(mode) {
case START_MODE : choices[0] = "Start Game"; break;
case PAUSE_MODE: choices[0] = "Continue"; break;
case GMOVR_MODE: choices[0] = ""; break;
defualt: choices[0] = "Start Game"; break;
}
int height; int height;
int width; int width;
int ch; int ch;

View file

@ -1,4 +1,5 @@
#include "../include/input.h" #include "../include/input.h"
#include "../include/gui.h"
#include <ncurses.h> #include <ncurses.h>
/* Returns 1 to continue, 0 if quit requested (player inactive). */ /* Returns 1 to continue, 0 if quit requested (player inactive). */
@ -22,9 +23,18 @@ int process_input(int input,
} }
} else if (input == 'p') { } else if (input == 'p') {
*pause = !(*pause); *pause = !(*pause);
} else if (input == 'q') {
/* signal to caller to quit by marking player inactive */ int choice = print_menu(stdscr, PAUSE_MODE);
return 0;
switch(choice) {
case 0: {
werase(stdscr);
mvprintw(LINES-1, 1, "p per pausa");
*pause = !(*pause);
break;
}
case 1: return 0; break;
}
} else if (input == 'g') { } else if (input == 'g') {
*auto_shoot = !(*auto_shoot); *auto_shoot = !(*auto_shoot);
} }

View file

@ -15,12 +15,12 @@ int main(void) {
init_colors(); init_colors();
/* show menu */ /* show menu */
int choice = print_menu(stdscr); int choice = print_menu(stdscr, START_MODE);
switch(choice) { switch(choice) {
case 0: { case 0: {
werase(stdscr); werase(stdscr);
mvprintw(1, 1, "p per pausa, q per uscire"); mvprintw(LINES-1, 1, "p per pausa");
refresh(); refresh();
game_run(); game_run();
break; break;