-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
95 lines (88 loc) · 3.82 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
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phelebra <xhelp00@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/10 16:50:14 by jbartosi #+# #+# */
/* Updated: 2023/10/16 16:05:02 by phelebra ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void handle_other_choices(int choice, t_box *box)
{
if (choice == 4)
{
printf("Exiting...\n");
box->exit_menu = 1;
exit(0);
}
else if (choice == 5)
{
if (box->music)
{
box->music = 0;
printf("Music turned off.\n");
}
else if (!box->music)
{
box->music = 1;
printf("Music turned on.\n");
}
}
else
printf("Invalid choice. Please enter a number between 1 and 5.\n");
}
void process_choice(int choice, t_box *box)
{
if (choice >= 1 && choice <= 3)
set_map_filename(choice, box);
else
handle_other_choices(choice, box);
}
void print_menu(void)
{
printf("\n ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ \n");
printf(" ██╔════╝ ██║ ██║ ██╔══██╗ ╚════██╗ ██╔══██╗ \n");
printf(" ██║ ██║ ██║ ██████╔╝ █████╔╝ ██║ ██║ \n");
printf(" ██║ ██║ ██║ ██╔══██╗ ╚═══██╗ ██║ ██║ \n");
printf(" ╚██████╗ ╚██████╔╝ ██████╔╝ ██████╔╝ ██████╔╝ \n");
printf(" ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ \n");
printf(" \n");
printf(" 42 project presented by jbartosi & phelebra \n");
printf(" \n");
printf(" ██╗ ███████╗ █████╗ █████╗ ██████╗ \n");
printf(" ██║ ██╔════╝ ██╔══██╗ ██╔══██╗ ██╔════╝ \n");
printf(" ██║ ███████╗ ███████║ ███████║ ██║ \n");
printf(" ██║ ╚════██║ ██╔══██║ ██╔══██║ ██║ \n");
printf(" ██║ ███████║ ██║ ██║ ██║ ██║ ╚██████╗ \n");
printf(" ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ v1.42\n");
printf(" \n");
printf("Terminal Menu:\n");
printf("1. Choose map hell\n");
printf("2. Choose map arena\n");
printf("3. Choose map exampleTexture\n");
printf("4. Exit\n");
printf("5. Toggle Music On/Off\n");
printf("Enter your choice (1-5): ");
}
void get_user_input(t_box *box)
{
int choice;
choice = 0;
if (scanf("%d", &choice) != 1)
{
while (getchar() != '\n')
continue ;
}
process_choice(choice, box);
}
void menu(t_box *box)
{
while (!box->map_filename && !box->exit_menu)
{
print_menu();
get_user_input(box);
}
}