-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:(vSKAH): Collectibles load errors fix:(vSKAH): Exit solve add:(vSKAH): Xpm find security add:(vSKAH): Add parsing errors TODO: print nb of movements
- Loading branch information
Showing
14 changed files
with
467 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* errors_utils.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/13 17:50:08 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/13 17:50:08 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
#include <fcntl.h> | ||
|
||
int handle_file_error(char *argv[]) | ||
{ | ||
int fd; | ||
|
||
if (!argv[1]) | ||
return (ft_putstr_fd("Error\n -> Invalid file path.\n", 1), -2); | ||
fd = open(argv[1], O_RDONLY); | ||
if (fd == -1) | ||
return (ft_putstr_fd("Error\n -> Invalid file path.\n", 1), -2); | ||
return (fd); | ||
} | ||
|
||
int handle_map_error(char *path, t_game game) | ||
{ | ||
int elements_code; | ||
t_world cloned; | ||
|
||
if (has_illegal_character(game.world)){ | ||
free_map(&game.world); | ||
free_collectibles(game.world.player.collectibles); | ||
return (ft_putstr_fd("Error\n -> Invalid Map / illegal character", 1), -1); | ||
|
||
} | ||
if (!is_valid_shape(game.world)) | ||
{ | ||
free_map(&game.world); | ||
free_collectibles(game.world.player.collectibles); | ||
return (ft_putstr_fd("Error\n -> Invalid shape / not closed", 1), -1); | ||
} | ||
elements_code = valid_elements(game.world); | ||
if (elements_code < 0) | ||
{ | ||
ft_putstr_fd("Error\n -> Please, check your map !", 1); | ||
ft_putstr_fd("\nThe map must contains 1 E, 1 P, minimum 1 C", 1); | ||
return (-1); | ||
} | ||
load_map(open(path, O_RDONLY), path, &cloned); | ||
is_solvable(cloned.map, game.world.player.location.x, game.world.player.location.y, game.world.length_y); | ||
if (count_element(cloned, 'C') > 0 || count_element(cloned, 'E') > 0) | ||
{ | ||
ft_putstr_fd("Error\n -> Sorry, your map is not resolvable", 1); | ||
free_map(&game.world); | ||
free_collectibles(game.world.player.collectibles); | ||
return (free_map(&cloned), -2); | ||
} | ||
free_map(&cloned); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,47 +6,75 @@ | |
/* By: jbadaire <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/10/03 10:21:10 by jbadaire #+# #+# */ | ||
/* Updated: 2023/10/12 19:51:21 by jbadaire ### ########.fr */ | ||
/* Updated: 2023/10/13 17:09:19 by jbadaire ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "so_long.h" | ||
|
||
void free_map(t_world *world) { | ||
int index; | ||
void free_map(t_world *world) | ||
{ | ||
int index; | ||
|
||
index = 0; | ||
while (world->map && world->map[index]) { | ||
while (world->map && world->map[index]) | ||
{ | ||
free(world->map[index]); | ||
index++; | ||
} | ||
free((world->map)); | ||
} | ||
|
||
|
||
void free_textures(t_game *game) | ||
void free_textures(t_game *game) | ||
{ | ||
t_textures *textures = &game->textures; | ||
if(textures->wall.is_set) | ||
t_textures *textures; | ||
|
||
textures = &game->textures; | ||
if (textures->wall.is_set && textures->wall.texture != NULL) | ||
mlx_destroy_image(game->mlx, game->textures.wall.texture); | ||
if(textures->player.is_set) | ||
if (textures->player.is_set && textures->player.texture != NULL) | ||
mlx_destroy_image(game->mlx, game->textures.player.texture); | ||
if(textures->collectible.is_set) | ||
if (textures->collectible.is_set && textures->collectible.texture != NULL) | ||
mlx_destroy_image(game->mlx, game->textures.collectible.texture); | ||
if(textures->grass.is_set) | ||
if (textures->grass.is_set && textures->grass.texture != NULL) | ||
mlx_destroy_image(game->mlx, game->textures.grass.texture); | ||
if(textures->exit.is_set) | ||
if (textures->exit.is_set && textures->exit.texture != NULL) | ||
mlx_destroy_image(game->mlx, game->textures.exit.texture); | ||
} | ||
|
||
void free_collectibles(t_collectible *collectible) | ||
void free_collectibles(t_collectible *collectible) | ||
{ | ||
t_collectible *copy; | ||
t_collectible *copy; | ||
|
||
while (collectible != NULL) | ||
{ | ||
copy = collectible; | ||
collectible = collectible->next; | ||
free(copy); | ||
} | ||
} | ||
} | ||
|
||
int free_unavailable_texture(t_game game) | ||
{ | ||
if (has_unavailable_texture(game.textures)) | ||
{ | ||
ft_putstr_fd("Error\n -> Textures can't be loaded.", 1); | ||
free_map(&game.world); | ||
free_textures(&game); | ||
free_collectibles(game.world.player.collectibles); | ||
mlx_destroy_display(game.mlx); | ||
free(game.mlx); | ||
return (1); | ||
} | ||
return (0); | ||
} | ||
|
||
void destroy(t_game *game) | ||
{ | ||
free_map(&game->world); | ||
free_textures(game); | ||
free_collectibles(game->world.player.collectibles); | ||
mlx_destroy_window(game->mlx, game->window); | ||
mlx_destroy_display(game->mlx); | ||
free(game->mlx); | ||
} |
Oops, something went wrong.