From 723e7da22f36d4ee80b24de336a492581a0d53aa Mon Sep 17 00:00:00 2001 From: "tanguy.cavagna" <tanguy.cavagna@etu.hesge.ch> Date: Thu, 12 May 2022 10:22:14 +0200 Subject: [PATCH] Better menu and returning to menu handling --- main.c | 16 ++++++---------- ui/ui.c | 19 ++++++++++++++----- wordle/wordle.c | 6 ++++++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index c59f3d5..a96476d 100644 --- a/main.c +++ b/main.c @@ -9,17 +9,13 @@ int main(void) { setlocale(LC_ALL, ""); init_term(); + int menu_choice; - int menu_choice = show_menu(); - - if (menu_choice == MENU_QUIT) { - cleanup_term(); - return EXIT_SUCCESS; - } - - clear(); - set_gamemode(menu_choice); - launch_game(); + while ((menu_choice = show_menu()) != MENU_QUIT) { + clear(); + set_gamemode(menu_choice); + launch_game(); + }; cleanup_term(); diff --git a/ui/ui.c b/ui/ui.c index 44eef2d..e27d45c 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -44,6 +44,17 @@ void draw_menu(int menu_item) { } } +/** + * @brief Hide the help subwindow + */ +void hide_help() { + wclear(ui_window); + delwin(help); + refresh(); + + help = NULL; +} + //========================== // PUBLIC //========================== @@ -80,6 +91,8 @@ void cleanup_term() { } int show_menu() { + hide_help(); + char title[8][64] = {"$$\\ $$\\ $$$$$$\\ $$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$$$\\ ", "$$ | $\\ $$ |$$ __$$\\ $$ __$$\\ $$ __$$\\ $$ | $$ _____|", "$$ |$$$\\ $$ |$$ / $$ |$$ | $$ |$$ | $$ |$$ | $$ | ", @@ -133,11 +146,7 @@ int show_menu() { void toggle_help() { // Delete existing instance of the subwindow if (help != NULL) { - wclear(ui_window); - delwin(help); - refresh(); - - help = NULL; + hide_help(); return; } diff --git a/wordle/wordle.c b/wordle/wordle.c index 41dd5f7..f5ed703 100644 --- a/wordle/wordle.c +++ b/wordle/wordle.c @@ -15,6 +15,12 @@ int current_try_letter_id = 0; * @brief Initialize the game */ void initialize_game() { + // Reset game variables + _game_finished = false; + current_try_id = 0; + current_try_letter_id = 0; + + // Tries and answer setup chosen_word = "SALUT"; // Must be randomly picked in a dictionary tries = calloc(TRIES_COUNT, sizeof(char *)); -- GitLab