Skip to content

Commit

Permalink
add:(vSKAH): Correct way to quit game.
Browse files Browse the repository at this point in the history
add:(vSKAH): Map test
fix:(vSKAH): Fix norm errors
fix:(vSKAH): Fix parsing leaks / errors
  • Loading branch information
vSKAH committed Oct 20, 2023
1 parent 78f6cd2 commit 03ced6a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
10 changes: 5 additions & 5 deletions errors_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion frees.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions graphics_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions maps/valid_2.ber
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
111111111111111111
10000000000C000001
100P00000000000C01
1000000C0000000001
1000C0000000010001
100000000000101001
1000000C0000010E01
111111111111111111
2 changes: 2 additions & 0 deletions so_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 03ced6a

Please sign in to comment.