From 03ced6a70da2f67bd242166578cc14749cb3608e Mon Sep 17 00:00:00 2001 From: vSKAH Date: Fri, 20 Oct 2023 12:18:06 +0200 Subject: [PATCH] add:(vSKAH): Correct way to quit game. add:(vSKAH): Map test fix:(vSKAH): Fix norm errors fix:(vSKAH): Fix parsing leaks / errors --- errors_utils.c | 10 +++++----- frees.c | 2 +- graphics_utils.c | 7 +++++++ maps/valid_2.ber | 8 ++++++++ so_long.h | 2 ++ 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 maps/valid_2.ber diff --git a/errors_utils.c b/errors_utils.c index 5f44864..2135470 100644 --- a/errors_utils.c +++ b/errors_utils.c @@ -25,7 +25,7 @@ int handle_file_error(char *argv[]) if (fd == -1) { ft_printf("Error\n -> Can't open file.\n"); - ft_printf("please check permissions or path: %s", argv[1]); + ft_printf("please check permissions or path: %s\n", argv[1]); return (-2); } return (fd); @@ -40,7 +40,7 @@ t_boolean handle_map_solve(char *path, t_game game) game.world.player.location.y, game.world.length_y); if (count_element(cloned, 'C') > 0 || count_element(cloned, 'E') > 0) { - ft_printf("Error\n -> Sorry, your map is not resolvable"); + ft_printf("Error\n -> Sorry, your map is not resolvable\n"); free_collectibles(game.world.player.collectibles); return (free_map(&game.world), free_map(&cloned), -2); } @@ -55,7 +55,7 @@ int handle_elements_error(char *path, t_game game) elements_code = valid_elements(game.world); if (elements_code < 0) { - ft_printf("Error\n -> Map must contains 1 E, 1 P, minimum 1 C"); + ft_printf("Error\n -> Map must contains 1 E, 1 P, minimum 1 C\n"); free_collectibles(game.world.player.collectibles); free_map(&game.world); return (-1); @@ -68,12 +68,12 @@ int handle_map_error(t_game game) if (has_illegal_character(game.world)) { free_map(&game.world); - return (ft_printf("Error\n -> Invalid Map / illegal character"), -1); + return (ft_printf("Error\n -> Invalid Map / illegal character\n"), -1); } if (!is_valid_shape(game.world)) { free_map(&game.world); - return (ft_printf("Error\n -> Invalid shape / not closed"), -1); + return (ft_printf("Error\n -> Invalid shape / not closed\n"), -1); } return (0); } diff --git a/frees.c b/frees.c index 91f60a2..2a2b746 100644 --- a/frees.c +++ b/frees.c @@ -58,7 +58,7 @@ int free_unavailable_texture(t_game game) { if (has_unavailable_texture(game.textures)) { - ft_printf("Error\n -> Textures can't be loaded."); + ft_printf("Error\n -> Textures can't be loaded.\n"); free_map(&game.world); free_textures(&game); free_collectibles(game.world.player.collectibles); diff --git a/graphics_utils.c b/graphics_utils.c index 97d93db..9908598 100644 --- a/graphics_utils.c +++ b/graphics_utils.c @@ -12,6 +12,12 @@ #include "so_long.h" +int mlx_loop_cancel(t_game *game) +{ + mlx_loop_end(game->mlx); + return (1); +} + int init_graphics_part(t_game *game) { game->mlx = mlx_init(); @@ -25,6 +31,7 @@ int init_graphics_part(t_game *game) 128 * game->world.length_y, "Xe'Burger"); draws(*game); mlx_hook(game->window, 2, (1L << 0), on_player_move, game); + mlx_hook(game->window, 17, 0L, mlx_loop_cancel, game); mlx_loop(game->mlx); return (0); } diff --git a/maps/valid_2.ber b/maps/valid_2.ber new file mode 100644 index 0000000..3a5b25a --- /dev/null +++ b/maps/valid_2.ber @@ -0,0 +1,8 @@ +111111111111111111 +10000000000C000001 +100P00000000000C01 +1000000C0000000001 +1000C0000000010001 +100000000000101001 +1000000C0000010E01 +111111111111111111 diff --git a/so_long.h b/so_long.h index 66f9629..2cc9693 100644 --- a/so_long.h +++ b/so_long.h @@ -72,6 +72,8 @@ t_boolean loc_equals(t_location loc_1, t_location loc_2); t_boolean is_inside_world(int y, int x, t_world world); t_boolean ft_endwith(char *src, char *pattern); int init_graphics_part(t_game *game); +int mlx_loop_cancel(t_game *game); + // ** ERRORS **// int handle_file_error(char *argv[]); int handle_map_error(t_game game);