diff --git a/main.c b/main.c index c59f3d58c67c07fc12c72a510d06a1ea60312b5a..a96476dc534df3f125eba05b76fca3f08c07bffc 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 44eef2d05db0cf39b8ced8d1e727e53ebbf36bab..e27d45cd2490d141658191ed3beb2e370cebf65f 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 41dd5f766d95aea86f12c33b98f31fd14febe2c8..f5ed703b5a3cc8f01a1423069d5e9fcb417f9007 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 *));