diff --git a/.ber b/.ber new file mode 100644 index 0000000..e69de29 diff --git a/ft_check_map_error.c b/ft_check_map_error.c index c47f8a9..f51b7e6 100644 --- a/ft_check_map_error.c +++ b/ft_check_map_error.c @@ -6,13 +6,16 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/17 10:17:52 by adjoly #+# #+# */ -/* Updated: 2024/01/22 13:24:41 by adjoly ### ########.fr */ +/* Updated: 2024/01/24 12:35:46 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "libft/libft.h" #include "printf/ft_printf.h" #include "so_long.h" #include +#include +#include char ft_check_charset(char c, char *charset) { @@ -34,7 +37,11 @@ char ft_check_file(char *file_name) fd = open(file_name, O_RDONLY); if (fd < 1) + { + close(fd); return (1); + } + close(fd); return (0); } @@ -49,7 +56,7 @@ char ft_valid_char(char **map) x = 0; while (map[y][x]) { - if (ft_check_charset(map[y][x], "01CEP\n") == 1) + if (ft_check_charset(map[y][x], "01CEP") == 1) return (1); x++; } @@ -58,93 +65,154 @@ char ft_valid_char(char **map) return (0); } -char ft_check_player(char **map) +char ft_check_element(char **map, t_coords *p_coords) { size_t y; size_t x; size_t p_count; - - y = 0; - p_count = 0; - while (map[y]) - { - x = 0; - while (map[y][x]) - { - if (map[y][x] == 'P') - p_count++; - x++; - } - y++; - } - if (p_count == 1) - return (0); - return (1); -} - -char ft_check_exit(char **map) -{ - size_t y; - size_t x; - size_t p_count; - - y = 0; - p_count = 0; - while (map[y]) - { - x = 0; - while (map[y][x]) - { - if (map[y][x] == 'E') - p_count++; - x++; - } - y++; - } - if (p_count == 1) - return (0); - return (1); -} - -char ft_check_collectible(char **map) -{ - size_t y; - size_t x; + size_t e_count; size_t c_count; y = 0; + p_count = 0; + e_count = 0; c_count = 0; while (map[y]) { x = 0; while (map[y][x]) { - if (map[y][x] == 'C') + if (map[y][x] == 'P') + { + p_count++; + p_coords->x = x; + p_coords->y = y; + } + else if (map[y][x] == 'E') + e_count++; + else if (map[y][x] == 'C') c_count++; x++; } y++; } - if (c_count >= 1) - return (0); - return (1); + if (p_count != 1) + return (1); + else if (e_count != 1) + return (2); + else if (c_count < 1) + return (3); + return (0); } -/*char ft_floodfill(char **map) +void ft_flood(int x, int y, char **map) { - while (expression) + if (map[y][x] != '1') { - + map[y][x] = '1'; + ft_flood(x - 1, y, map); + ft_flood(x + 1, y, map); + ft_flood(x, y - 1, map); + ft_flood(x, y + 1, map); } - // partir dans toutes les direction a partir du P et sur tout les point suivant -}*/ +} + +char ft_floodfill(char **map, t_coords *p_coords) +{ + size_t x; + size_t y; + + ft_flood(p_coords->x, p_coords->y, map); + y = 0; + while (map[y]) + { + x = 0; + while (map[y][x]) + { + if (map[y][x] == 'C' || map[y][x] == 'E') + return (1); + x++; + } + y++; + } + return (0); +} + +char ft_checkline(char *map_line, char c) +{ + unsigned short i; + + i = 0; + while (*map_line && i < USHRT_MAX) + { + if (*map_line != c) + return (1); + map_line++; + i++; + } + return (0); +} + +char ft_checkcol(char **map, char c, unsigned short col) +{ + unsigned short i; + + i = 0; + while (map[i] && i < USHRT_MAX) + { + if (map[i][col] != c) + return (1); + i++; + } + return (0); +} + +char ft_is_closed(char **map) +{ + unsigned short size_map; + unsigned short size_line; + unsigned short i; + unsigned short res; + + i = 0; + size_map = ft_mapsize(map); + size_line = ft_strlen(map[0]); + res = ft_checkcol(map, '1', 0); + res += ft_checkcol(map, '1', size_line - 1); + res += ft_checkline(map[0], '1'); + res += ft_checkline(map[size_map - 1], '1'); + if (res > 0) + return (1); + return (0); +} + +char ft_is_empty(char **map) +{ + if (map[0][0] == '\0') + return (1); + return (0); +} + +char ft_is_rectangular(char **map) +{ + size_t len_map; + + len_map = ft_strlen(*map); + while (*map) + { + if (ft_strlen(*map) != len_map) + return (1); + map++; + } + return (0); +} char ft_valid_file_ext(char *file_name) { unsigned short file_len; file_len = ft_strlen(file_name) - 1; - if (file_len < 3) + if (file_len <= 3) return (1); else if (file_name[file_len] == 'r' && file_name[file_len - 1] == 'e' \ && file_name[file_len - 2] == 'b' && file_name[file_len - 3] == '.') @@ -163,15 +231,50 @@ void ft_send_error(char *msg, char **map) void ft_check_map_error(char **map) { + char check_result; + t_coords *p_coords; + + p_coords = malloc(sizeof(t_coords)); + if (ft_is_empty(map) == 1) + { + free(p_coords); + ft_send_error("Map is empty", map); + } if (ft_valid_char(map) == 1) + { + free(p_coords); ft_send_error("Invalid character in map\n", map); - else if (ft_check_player(map) == 1) + } + if (ft_is_rectangular(map) == 1) + { + free(p_coords); + ft_send_error("Map is not rectengular\n", map); + } + check_result = ft_check_element(map, p_coords); + if (check_result == 1) + { + free(p_coords); ft_send_error("Invalid number of player\n", map); - else if (ft_check_collectible(map) == 1) - ft_send_error("Invalid number of collectible\n", map); - else if (ft_check_exit(map) == 1) + } + if (check_result == 2) + { + free(p_coords); ft_send_error("Invalid number of exit\n", map); - // else if () - // else if (ft_floodfill(map) == 1) - // ft_send_error("Map is cannot be finished\n", map); + } + if (check_result == 3) + { + free(p_coords); + ft_send_error("Invalid number of collectible\n", map); + } + if (ft_is_closed(map) == 1) + { + free(p_coords); + ft_send_error("Map is not closed\n", map); + } + if (ft_floodfill(map, p_coords) == 1) + { + free(p_coords); + ft_send_error("Map is cannot be finished\n", map); + } + free(p_coords); } diff --git a/ft_check_map_error.o b/ft_check_map_error.o deleted file mode 100644 index 5aadef6..0000000 Binary files a/ft_check_map_error.o and /dev/null differ diff --git a/ft_move_character.c b/ft_move_character.c index a982390..a9b8327 100644 --- a/ft_move_character.c +++ b/ft_move_character.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/07 19:13:01 by adjoly #+# #+# */ -/* Updated: 2024/01/21 15:29:10 by adjoly ### ########.fr */ +/* Updated: 2024/01/24 12:16:14 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ void ft_move_up(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P'); win->c_count--; win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->p_coords->y == win->e_coords->y && win->e_coords->x == win->p_coords->x @@ -29,6 +30,7 @@ void ft_move_up(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E'); ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'E' && win->c_count == 0) @@ -41,6 +43,7 @@ void ft_move_up(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, '0'); ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } } @@ -53,6 +56,7 @@ void ft_move_down(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P'); win->c_count--; win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->p_coords->y == win->e_coords->y && win->e_coords->x == win->p_coords->x @@ -61,6 +65,7 @@ void ft_move_down(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E'); ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->map[win->p_coords->y + 1][win->p_coords->x] == 'E' && win->c_count == 0) @@ -73,6 +78,7 @@ void ft_move_down(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, '0'); ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } } @@ -85,6 +91,7 @@ void ft_move_left(t_window *win) ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P'); win->c_count--; win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->p_coords->y == win->e_coords->y && win->e_coords->x == win->p_coords->x @@ -93,6 +100,7 @@ void ft_move_left(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E'); ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->map[win->p_coords->y][win->p_coords->x - 1] == 'E' && win->c_count == 0) @@ -105,6 +113,7 @@ void ft_move_left(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, '0'); ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } } @@ -117,6 +126,7 @@ void ft_move_right(t_window *win) ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P'); win->c_count--; win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->p_coords->y == win->e_coords->y && win->e_coords->x == win->p_coords->x @@ -125,6 +135,7 @@ void ft_move_right(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E'); ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } else if (win->map[win->p_coords->y][win->p_coords->x + 1] == 'E' && win->c_count == 0) @@ -137,6 +148,7 @@ void ft_move_right(t_window *win) ft_putimg(win->p_coords->x, win->p_coords->y, win, '0'); ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P'); win->mov_count++; + ft_printf("Mouvement : %d\n", win->mov_count); } } @@ -155,6 +167,5 @@ int ft_key_event(int key, void *param) ft_move_left(win); else if (key == 7 || key == 79) ft_move_right(win); - ft_printf("Mouvement : %d\n", win->mov_count); return (0); } diff --git a/ft_move_character.o b/ft_move_character.o deleted file mode 100644 index 7797a68..0000000 Binary files a/ft_move_character.o and /dev/null differ diff --git a/get_map.c b/get_map.c index 593735f..4bbe8c6 100644 --- a/get_map.c +++ b/get_map.c @@ -6,65 +6,77 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/08 13:13:18 by adjoly #+# #+# */ -/* Updated: 2024/01/19 17:14:11 by adjoly ### ########.fr */ +/* Updated: 2024/01/23 11:45:20 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "printf/ft_printf.h" #include "so_long.h" +#include -size_t ft_countline_fd(char *file_name) +size_t ft_filesize(char *file_name) { - size_t line_count; + size_t i; + int fd; ssize_t rd; char *buf; - size_t i; - int fd; fd = open(file_name, O_RDONLY); - if (fd < 1) + buf = ft_calloc(1, 1); + if (!buf) return (0); i = 0; - line_count = 0; - buf = ft_calloc(1, 1); - while (i < ULONG_MAX) + while (buf && i < SIZE_MAX) { rd = read(fd, buf, 1); - if (rd == -1 || rd == 0) + if (rd <= 0) break ; - else if (buf[0] == '\n') - line_count++; i++; } - close(fd); free(buf); - return (line_count); + close(fd); + return (i); } -char **ft_read_map(char *file_name) +char **ft_getmap(int fd, char **map_read, char *buf, char *tmp) { - char **map_read; - int fd; + ssize_t rd; size_t i; - size_t ln_count; i = 0; - ln_count = ft_countline_fd(file_name); - if (ln_count == 0) - return (NULL); - fd = open(file_name, O_RDONLY); - map_read = ft_calloc(sizeof(char *), ln_count); - if (!map_read) + while (buf && i < SIZE_MAX) { - close (fd); - return (NULL); - } - while (i < ULONG_MAX) - { - map_read[i] = get_next_line(fd); - if (map_read[i] == NULL) + rd = read(fd, buf, 1); + if (rd <= 0) break ; + tmp[i] = buf[0]; i++; } close(fd); + tmp[i] = '\0'; + map_read = ft_split(tmp, '\n'); + return (map_read); +} + +char **ft_read_map(char *file_name, char **map_read) +{ + int fd; + char *tmp; + char *buf; + size_t filesize; + + filesize = ft_filesize(file_name); + if (filesize == 0) + return (NULL); + tmp = ft_calloc(filesize + 1, 1); + if (!tmp) + return (NULL); + buf = ft_calloc(1, 1); + if (!buf) + return (NULL); + fd = open(file_name, O_RDONLY); + map_read = ft_getmap(fd, map_read, buf, tmp); + free(buf); + free(tmp); return (map_read); } diff --git a/get_map.o b/get_map.o deleted file mode 100644 index 5ff4b7d..0000000 Binary files a/get_map.o and /dev/null differ diff --git a/get_next_line/get_next_line.a b/get_next_line/get_next_line.a deleted file mode 100644 index 2ad8e08..0000000 Binary files a/get_next_line/get_next_line.a and /dev/null differ diff --git a/get_next_line/get_next_line.o b/get_next_line/get_next_line.o deleted file mode 100644 index b0bbd67..0000000 Binary files a/get_next_line/get_next_line.o and /dev/null differ diff --git a/get_next_line/get_next_line_utils.o b/get_next_line/get_next_line_utils.o deleted file mode 100644 index c8c7179..0000000 Binary files a/get_next_line/get_next_line_utils.o and /dev/null differ diff --git a/libft/ft_atoi.o b/libft/ft_atoi.o deleted file mode 100644 index afb0010..0000000 Binary files a/libft/ft_atoi.o and /dev/null differ diff --git a/libft/ft_bzero.o b/libft/ft_bzero.o deleted file mode 100644 index 62d7f17..0000000 Binary files a/libft/ft_bzero.o and /dev/null differ diff --git a/libft/ft_calloc.o b/libft/ft_calloc.o deleted file mode 100644 index 6fada56..0000000 Binary files a/libft/ft_calloc.o and /dev/null differ diff --git a/libft/ft_isalnum.o b/libft/ft_isalnum.o deleted file mode 100644 index aecf709..0000000 Binary files a/libft/ft_isalnum.o and /dev/null differ diff --git a/libft/ft_isalpha.o b/libft/ft_isalpha.o deleted file mode 100644 index 0bd62e8..0000000 Binary files a/libft/ft_isalpha.o and /dev/null differ diff --git a/libft/ft_isascii.o b/libft/ft_isascii.o deleted file mode 100644 index 11cdcbf..0000000 Binary files a/libft/ft_isascii.o and /dev/null differ diff --git a/libft/ft_isdigit.o b/libft/ft_isdigit.o deleted file mode 100644 index 9473b5f..0000000 Binary files a/libft/ft_isdigit.o and /dev/null differ diff --git a/libft/ft_isprint.o b/libft/ft_isprint.o deleted file mode 100644 index fa1d564..0000000 Binary files a/libft/ft_isprint.o and /dev/null differ diff --git a/libft/ft_itoa.o b/libft/ft_itoa.o deleted file mode 100644 index 9d54483..0000000 Binary files a/libft/ft_itoa.o and /dev/null differ diff --git a/libft/ft_lstadd_back.o b/libft/ft_lstadd_back.o deleted file mode 100644 index 83158d2..0000000 Binary files a/libft/ft_lstadd_back.o and /dev/null differ diff --git a/libft/ft_lstadd_front.o b/libft/ft_lstadd_front.o deleted file mode 100644 index c480e34..0000000 Binary files a/libft/ft_lstadd_front.o and /dev/null differ diff --git a/libft/ft_lstclear.o b/libft/ft_lstclear.o deleted file mode 100644 index 3b791fb..0000000 Binary files a/libft/ft_lstclear.o and /dev/null differ diff --git a/libft/ft_lstdelone.o b/libft/ft_lstdelone.o deleted file mode 100644 index b0055fa..0000000 Binary files a/libft/ft_lstdelone.o and /dev/null differ diff --git a/libft/ft_lstiter.o b/libft/ft_lstiter.o deleted file mode 100644 index 4fc4d3a..0000000 Binary files a/libft/ft_lstiter.o and /dev/null differ diff --git a/libft/ft_lstlast.o b/libft/ft_lstlast.o deleted file mode 100644 index af009cf..0000000 Binary files a/libft/ft_lstlast.o and /dev/null differ diff --git a/libft/ft_lstmap.o b/libft/ft_lstmap.o deleted file mode 100644 index f038204..0000000 Binary files a/libft/ft_lstmap.o and /dev/null differ diff --git a/libft/ft_lstnew.o b/libft/ft_lstnew.o deleted file mode 100644 index e258459..0000000 Binary files a/libft/ft_lstnew.o and /dev/null differ diff --git a/libft/ft_lstsize.o b/libft/ft_lstsize.o deleted file mode 100644 index d476de5..0000000 Binary files a/libft/ft_lstsize.o and /dev/null differ diff --git a/libft/ft_memchr.o b/libft/ft_memchr.o deleted file mode 100644 index be0211d..0000000 Binary files a/libft/ft_memchr.o and /dev/null differ diff --git a/libft/ft_memcmp.o b/libft/ft_memcmp.o deleted file mode 100644 index f6e2703..0000000 Binary files a/libft/ft_memcmp.o and /dev/null differ diff --git a/libft/ft_memcpy.o b/libft/ft_memcpy.o deleted file mode 100644 index 6fec394..0000000 Binary files a/libft/ft_memcpy.o and /dev/null differ diff --git a/libft/ft_memmove.o b/libft/ft_memmove.o deleted file mode 100644 index 02381d8..0000000 Binary files a/libft/ft_memmove.o and /dev/null differ diff --git a/libft/ft_memset.o b/libft/ft_memset.o deleted file mode 100644 index 936618d..0000000 Binary files a/libft/ft_memset.o and /dev/null differ diff --git a/libft/ft_putchar_fd.o b/libft/ft_putchar_fd.o deleted file mode 100644 index 786101f..0000000 Binary files a/libft/ft_putchar_fd.o and /dev/null differ diff --git a/libft/ft_putendl_fd.o b/libft/ft_putendl_fd.o deleted file mode 100644 index fedf787..0000000 Binary files a/libft/ft_putendl_fd.o and /dev/null differ diff --git a/libft/ft_putnbr_fd.o b/libft/ft_putnbr_fd.o deleted file mode 100644 index 82110de..0000000 Binary files a/libft/ft_putnbr_fd.o and /dev/null differ diff --git a/libft/ft_putstr_fd.o b/libft/ft_putstr_fd.o deleted file mode 100644 index b731fc0..0000000 Binary files a/libft/ft_putstr_fd.o and /dev/null differ diff --git a/libft/ft_split.o b/libft/ft_split.o deleted file mode 100644 index 31a281e..0000000 Binary files a/libft/ft_split.o and /dev/null differ diff --git a/libft/ft_strchr.o b/libft/ft_strchr.o deleted file mode 100644 index c5583ff..0000000 Binary files a/libft/ft_strchr.o and /dev/null differ diff --git a/libft/ft_strdup.o b/libft/ft_strdup.o deleted file mode 100644 index 5c511ad..0000000 Binary files a/libft/ft_strdup.o and /dev/null differ diff --git a/libft/ft_striteri.o b/libft/ft_striteri.o deleted file mode 100644 index 791eac5..0000000 Binary files a/libft/ft_striteri.o and /dev/null differ diff --git a/libft/ft_strjoin.o b/libft/ft_strjoin.o deleted file mode 100644 index 868baa1..0000000 Binary files a/libft/ft_strjoin.o and /dev/null differ diff --git a/libft/ft_strlcat.o b/libft/ft_strlcat.o deleted file mode 100644 index fffbf92..0000000 Binary files a/libft/ft_strlcat.o and /dev/null differ diff --git a/libft/ft_strlcpy.o b/libft/ft_strlcpy.o deleted file mode 100644 index e25b437..0000000 Binary files a/libft/ft_strlcpy.o and /dev/null differ diff --git a/libft/ft_strlen.o b/libft/ft_strlen.o deleted file mode 100644 index fec4953..0000000 Binary files a/libft/ft_strlen.o and /dev/null differ diff --git a/libft/ft_strmapi.o b/libft/ft_strmapi.o deleted file mode 100644 index 81a145a..0000000 Binary files a/libft/ft_strmapi.o and /dev/null differ diff --git a/libft/ft_strncmp.o b/libft/ft_strncmp.o deleted file mode 100644 index 1f797d9..0000000 Binary files a/libft/ft_strncmp.o and /dev/null differ diff --git a/libft/ft_strnstr.o b/libft/ft_strnstr.o deleted file mode 100644 index bfbe0b7..0000000 Binary files a/libft/ft_strnstr.o and /dev/null differ diff --git a/libft/ft_strrchr.o b/libft/ft_strrchr.o deleted file mode 100644 index aa9ce75..0000000 Binary files a/libft/ft_strrchr.o and /dev/null differ diff --git a/libft/ft_strtrim.o b/libft/ft_strtrim.o deleted file mode 100644 index d2ff71e..0000000 Binary files a/libft/ft_strtrim.o and /dev/null differ diff --git a/libft/ft_substr.o b/libft/ft_substr.o deleted file mode 100644 index d811f99..0000000 Binary files a/libft/ft_substr.o and /dev/null differ diff --git a/libft/ft_tolower.o b/libft/ft_tolower.o deleted file mode 100644 index 9fde8fe..0000000 Binary files a/libft/ft_tolower.o and /dev/null differ diff --git a/libft/ft_toupper.o b/libft/ft_toupper.o deleted file mode 100644 index 374dad9..0000000 Binary files a/libft/ft_toupper.o and /dev/null differ diff --git a/libft/libft.a b/libft/libft.a deleted file mode 100644 index bdc9914..0000000 Binary files a/libft/libft.a and /dev/null differ diff --git a/main.c b/main.c index 00ca61a..0fb5c36 100644 --- a/main.c +++ b/main.c @@ -6,11 +6,16 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/06 16:18:56 by adjoly #+# #+# */ -/* Updated: 2024/01/22 13:46:27 by adjoly ### ########.fr */ +/* Updated: 2024/01/24 12:17:09 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ +#include "MacroLibX/includes/mlx.h" +#include "printf/ft_printf.h" #include "so_long.h" +#include +#include +#include void ft_freeimg(t_window *win) { @@ -22,19 +27,30 @@ void ft_freeimg(t_window *win) free (win->img); } - -void ft_freemap(char **map) +size_t ft_mapsize(char **map) { size_t i; i = 0; - while (map[i] && i < ULONG_MAX) + while (*map && i < SIZE_MAX) + { + map++; + i++; + } + return (i); +} + +void ft_freemap(char **map) +{ + int i; + + i = 0; + while (map[i]) { - // ft_printf("freed : %s\n", map[i]); free(map[i]); i++; } - // free(map); + free(map); } int win_close(int event, void *param) @@ -51,11 +67,12 @@ void ft_exit(t_window *win) { ft_freeimg(win); mlx_destroy_window(win->mlx, win->win); + mlx_loop_end(win->mlx); mlx_destroy_display(win->mlx); ft_freemap(win->map); - // free(win->p_coords); - // free(win->e_coords); - // free(win); + free(win->p_coords); + free(win->e_coords); + free(win); exit (EXIT_SUCCESS); } @@ -63,6 +80,7 @@ int main(int ac, char **av) { t_window *win; char **map; + t_coords map_size; (void) ac; map = NULL; @@ -72,12 +90,18 @@ int main(int ac, char **av) ft_send_error("Invalid map file extension (not .ber)\n", map); if (ft_check_file(av[1]) == 1) ft_send_error("File cannot be opened or doesn't exist\n", map); - map = ft_read_map(av[1]); + map = ft_read_map(av[1], map); if (!map) exit(EXIT_SUCCESS); if (!map[0]) - ft_send_error("Map is empty", map); + ft_send_error("Map is empty\n", map); ft_check_map_error(map); + ft_freemap(map); + map = ft_read_map(av[1], map); + if (!map) + exit(EXIT_SUCCESS); + map_size.x = ft_strlen(map[0]); + map_size.y = ft_mapsize(map); win = malloc(sizeof(map) + sizeof(t_window)); if (!win) { @@ -92,13 +116,13 @@ int main(int ac, char **av) if (!win->mlx) // free map img win; return (0); - win->win = mlx_new_window(win->mlx, 1600, 900, "so_fluffy"); + win->win = mlx_new_window(win->mlx, map_size.x * T_SIZE, map_size.y * T_SIZE, "so_fluffy"); if (!win->win) // free map img win ; destroy mlx return (0); win->map = map; win->mov_count = 0; - mlx_on_event(win->mlx, win->win, MLX_WINDOW_EVENT, win_close, win->mlx); + mlx_on_event(win->mlx, win->win, MLX_WINDOW_EVENT, win_close, win); mlx_on_event(win->mlx, win->win, MLX_KEYDOWN, ft_key_event, win); ft_alloc_img(win); ft_printmap(win->map, win); diff --git a/main.o b/main.o deleted file mode 100644 index 266dc45..0000000 Binary files a/main.o and /dev/null differ diff --git a/map.ber b/map.ber index 242be01..63f1a56 100644 --- a/map.ber +++ b/map.ber @@ -1,5 +1,5 @@ 1111111111111 -10010000000C1 -1000011111001 -1P0011E000001 -1111111111111 +100100000C1E1 +100P010011101 +10C0110000001 +1111111111111 \ No newline at end of file diff --git a/map.txt.ber b/map.txt.ber new file mode 100644 index 0000000..63f1a56 --- /dev/null +++ b/map.txt.ber @@ -0,0 +1,5 @@ +1111111111111 +100100000C1E1 +100P010011101 +10C0110000001 +1111111111111 \ No newline at end of file diff --git a/print_map.o b/print_map.o deleted file mode 100644 index e234dbb..0000000 Binary files a/print_map.o and /dev/null differ diff --git a/printf/ft_printf.o b/printf/ft_printf.o deleted file mode 100644 index 5eaa2e2..0000000 Binary files a/printf/ft_printf.o and /dev/null differ diff --git a/printf/ft_putchar.o b/printf/ft_putchar.o deleted file mode 100644 index e31b0fe..0000000 Binary files a/printf/ft_putchar.o and /dev/null differ diff --git a/printf/ft_putnbr.o b/printf/ft_putnbr.o deleted file mode 100644 index 279ad48..0000000 Binary files a/printf/ft_putnbr.o and /dev/null differ diff --git a/printf/ft_putnbrbase.o b/printf/ft_putnbrbase.o deleted file mode 100644 index b8ef8dc..0000000 Binary files a/printf/ft_putnbrbase.o and /dev/null differ diff --git a/printf/ft_putstr.o b/printf/ft_putstr.o deleted file mode 100644 index 410f795..0000000 Binary files a/printf/ft_putstr.o and /dev/null differ diff --git a/printf/ft_strlen.o b/printf/ft_strlen.o deleted file mode 100644 index 0bbb64d..0000000 Binary files a/printf/ft_strlen.o and /dev/null differ diff --git a/printf/libftprintf.a b/printf/libftprintf.a deleted file mode 100644 index 93ec406..0000000 Binary files a/printf/libftprintf.a and /dev/null differ diff --git a/so_long b/so_long deleted file mode 100755 index 1cd61f4..0000000 Binary files a/so_long and /dev/null differ diff --git a/so_long.h b/so_long.h index 2e55eaa..ce032b3 100644 --- a/so_long.h +++ b/so_long.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */ -/* Updated: 2024/01/21 15:42:52 by adjoly ### ########.fr */ +/* Updated: 2024/01/24 12:15:45 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,8 +60,7 @@ int ft_key_event(int key, void *param); void ft_freemap(char **map); int check_wall(char **map, t_coords *player); -size_t ft_countline_fd(char *file_name); -char **ft_read_map(char *file_name); +char **ft_read_map(char *file_name, char **map_read); char ft_check_file(char *file_name); void ft_exit(t_window *win); @@ -74,5 +73,6 @@ void ft_alloc_img(t_window *win); char ft_valid_file_ext(char *file_name); void ft_send_error(char *msg, char **map); void ft_check_map_error(char **map); +size_t ft_mapsize(char **map); #endif \ No newline at end of file