Skip to content
Snippets Groups Projects
Commit 723e7da2 authored by tanguy.cavagna's avatar tanguy.cavagna :desktop:
Browse files

Better menu and returning to menu handling

parent cffb3ddd
Branches
No related tags found
No related merge requests found
...@@ -9,17 +9,13 @@ ...@@ -9,17 +9,13 @@
int main(void) { int main(void) {
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
init_term(); init_term();
int menu_choice;
int menu_choice = show_menu(); while ((menu_choice = show_menu()) != MENU_QUIT) {
clear();
if (menu_choice == MENU_QUIT) { set_gamemode(menu_choice);
cleanup_term(); launch_game();
return EXIT_SUCCESS; };
}
clear();
set_gamemode(menu_choice);
launch_game();
cleanup_term(); cleanup_term();
......
...@@ -44,6 +44,17 @@ void draw_menu(int menu_item) { ...@@ -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 // PUBLIC
//========================== //==========================
...@@ -80,6 +91,8 @@ void cleanup_term() { ...@@ -80,6 +91,8 @@ void cleanup_term() {
} }
int show_menu() { int show_menu() {
hide_help();
char title[8][64] = {"$$\\ $$\\ $$$$$$\\ $$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$$$\\ ", char title[8][64] = {"$$\\ $$\\ $$$$$$\\ $$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$$$\\ ",
"$$ | $\\ $$ |$$ __$$\\ $$ __$$\\ $$ __$$\\ $$ | $$ _____|", "$$ | $\\ $$ |$$ __$$\\ $$ __$$\\ $$ __$$\\ $$ | $$ _____|",
"$$ |$$$\\ $$ |$$ / $$ |$$ | $$ |$$ | $$ |$$ | $$ | ", "$$ |$$$\\ $$ |$$ / $$ |$$ | $$ |$$ | $$ |$$ | $$ | ",
...@@ -133,11 +146,7 @@ int show_menu() { ...@@ -133,11 +146,7 @@ int show_menu() {
void toggle_help() { void toggle_help() {
// Delete existing instance of the subwindow // Delete existing instance of the subwindow
if (help != NULL) { if (help != NULL) {
wclear(ui_window); hide_help();
delwin(help);
refresh();
help = NULL;
return; return;
} }
......
...@@ -15,6 +15,12 @@ int current_try_letter_id = 0; ...@@ -15,6 +15,12 @@ int current_try_letter_id = 0;
* @brief Initialize the game * @brief Initialize the game
*/ */
void initialize_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 chosen_word = "SALUT"; // Must be randomly picked in a dictionary
tries = calloc(TRIES_COUNT, sizeof(char *)); tries = calloc(TRIES_COUNT, sizeof(char *));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment