From 736c7f67f9910c15e4c14e74add24d51e078e3fe Mon Sep 17 00:00:00 2001 From: Nathalia Vitoria Buchholz Date: Fri, 7 Feb 2025 16:43:20 -0300 Subject: [PATCH] wip --- Makefile | 4 ++-- includes/so_long.h | 10 ++++++---- src/game_utils.c | 24 +++++++++++++++++------- src/get_map.c | 6 +++--- src/so_long.c | 4 ++-- src/utils_validation_map.c | 25 +++++++++++++++++++++---- src/validate_map.c | 38 ++++++++++++++++++++++++++------------ 7 files changed, 77 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 67f7deb..bfacddb 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: nbuchhol +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/01/03 12:09:52 by nbuchhol #+# #+# # -# Updated: 2025/02/05 15:04:30 by nbuchhol ### ########.fr # +# Updated: 2025/02/07 13:58:09 by nbuchhol ### ########.fr # # # # **************************************************************************** # @@ -38,7 +38,7 @@ libft/libft.a: @$(MAKE) -C libft minilibx/libmlx.a: - @$(MAKE) -C minilibx + @$(MAKE) -C minilibx > /dev/null 2>/dev/null %.o: %.c @${CC} ${CFLAGS} ${DEBUG_FLAGS} -c $^ -o $@ diff --git a/includes/so_long.h b/includes/so_long.h index 02b032c..b60fd9d 100644 --- a/includes/so_long.h +++ b/includes/so_long.h @@ -6,7 +6,7 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/03 12:15:22 by nbuchhol #+# #+# */ -/* Updated: 2025/02/05 18:02:14 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 16:36:21 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ typedef struct s_valid_check size_t qnt_exit; } t_valid_check; -typedef struct t_classMlx +typedef struct s_classMlx { void *mlx; void *win; @@ -44,6 +44,8 @@ typedef struct s_game char **map; size_t map_h; size_t map_w; + size_t player_x; + size_t player_y; } t_game; int count_lines(int file); @@ -56,11 +58,11 @@ void close_game(int fd, char **map, int error_code); int is_rectangle(t_game game); void free_map(char **map); void validate_file_name(char *name); -int valid_chars(t_game game); +int valid_chars(t_game game, t_valid_check *check); char **load_map(int map_fd, t_game *game); int error_handling(int error_code); int valid_map(char *map); -void open_screen(); +void open_screen(t_game *game); #endif // SO_LONG diff --git a/src/game_utils.c b/src/game_utils.c index 55aaaf9..2e1e475 100644 --- a/src/game_utils.c +++ b/src/game_utils.c @@ -6,20 +6,25 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/03 17:05:29 by nbuchhol #+# #+# */ -/* Updated: 2025/02/05 13:40:50 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 13:53:22 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/so_long.h" -void open_screen() +void open_screen(t_game *game) { - void *mlx; - void *mlx_win; + t_classMlx mlx_class; + int win_w; + int win_h; - mlx = mlx_init(); - mlx_win = mlx_new_window(mlx, 1920, 1080, "Hello world!"); - mlx_loop(mlx); + mlx_class.mlx = mlx_init(); + if (mlx_class.mlx == NULL) + exit(error_handling(0)); + win_w = game->map_w * 32; + win_h = game->map_h * 32; + mlx_class.win = mlx_new_window(mlx_class.mlx, win_w, win_h, "Hello world!"); + mlx_loop(mlx_class.mlx); } void close_game(int fd, char **map, int error_code) @@ -30,3 +35,8 @@ void close_game(int fd, char **map, int error_code) if (error_code > -1) exit(error_handling(error_code)); } + +void close_mlx(void *mlx) +{ + +} diff --git a/src/get_map.c b/src/get_map.c index 5d8bc25..11a9949 100644 --- a/src/get_map.c +++ b/src/get_map.c @@ -6,7 +6,7 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/28 15:36:32 by nbuchhol #+# #+# */ -/* Updated: 2025/02/03 16:40:57 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 11:49:44 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,10 +19,10 @@ char **load_map(int map_fd, t_game *game) game->map = malloc(sizeof(char *) * (game->map_h + 1)); line = get_next_line(map_fd); - if(!game->map || !line) + if (!game->map || !line) { if (!line) - write(1,"Sem Linha\n",11); + write(1, "Sem Linha\n", 11); return (NULL); } i = 0; diff --git a/src/so_long.c b/src/so_long.c index e7a4c57..58faafd 100644 --- a/src/so_long.c +++ b/src/so_long.c @@ -6,7 +6,7 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/03 12:12:47 by nbuchhol #+# #+# */ -/* Updated: 2025/02/05 13:41:14 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 12:15:43 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int main(int argc, char **argv) return (1); validate_file_name(argv[1]); valid_map(argv[1]); - write(1, "Validado OK - VAMBORA!\n",24); + write(1, "Validado OK - VAMBORA!\n", 24); open_screen(); return (0); } diff --git a/src/utils_validation_map.c b/src/utils_validation_map.c index 2470fd5..a7dd935 100644 --- a/src/utils_validation_map.c +++ b/src/utils_validation_map.c @@ -6,7 +6,7 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/24 13:55:48 by nbuchhol #+# #+# */ -/* Updated: 2025/02/05 12:53:23 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 16:42:52 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,28 +28,45 @@ int count_lines(int file) return (lines); } -static int is_valid_char(char c) +static int is_valid_char(char c, t_valid_check *check) { + if (c == 'P') + check->qnt_player++; + if (c == 'E') + check->qnt_exit++; + if (c == 'C') + check->qnt_collectibles++; return (ft_strchr("EPC10", c) != NULL); } -int valid_chars(t_game game) +int valid_chars(t_game game, t_valid_check *check) { size_t y; size_t x; y = 0; + check->qnt_collectibles = 0; + check->qnt_exit = 0; + check->qnt_player = 0; while (y < game.map_h) { x = 0; while (x < game.map_w - 1) { - if (!is_valid_char(game.map[y][x])) + if (!is_valid_char(game.map[y][x], check)) return (1); + if (game.map[y][x] == 'P' && check->qnt_player = 1) + { + game.player_x = x; + game.player_x = y; + } x++; } y++; } + if (check->qnt_collectibles == 0 || check->qnt_exit == 0 + || check->qnt_player == 0 || check->qnt_player > 1) + return (1); return (0); } diff --git a/src/validate_map.c b/src/validate_map.c index 7b9dfdd..24fce55 100644 --- a/src/validate_map.c +++ b/src/validate_map.c @@ -6,7 +6,7 @@ /* By: nbuchhol +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/09 09:58:46 by nbuchhol #+# #+# */ -/* Updated: 2025/02/05 12:40:16 by nbuchhol ### ########.fr */ +/* Updated: 2025/02/07 14:38:06 by nbuchhol ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ int valid_map(char *map_file) { int map_fd; t_game game; + t_valid_check check; map_fd = open(map_file, O_RDONLY); if (map_fd == -1) @@ -26,21 +27,11 @@ int valid_map(char *map_file) game.map = load_map(map_fd, &game); if (!game.map) close_game(map_fd, game.map, 2); - if (is_rectangle(game) || valid_chars(game)) + if (is_rectangle(game) || valid_chars(game, &check)) close_game(map_fd, game.map, 2); return (0); } -// int flood_fill(char **map) -// { -// int x; -// int y; - -// x = 0; -// y = 0; - -// } - void validate_file_name(char *name) { size_t name_len; @@ -69,3 +60,26 @@ int is_rectangle(t_game game) } return (0); } + +void flood_fill(t_game *game, t_valid_check *check) +{ + int x; + int y; + + y = 0; + while (y < game-> map_h) + { + x = 0; + while (x < game->map_w - 1) + { + if (game->map[y][x] == 'P') + check->qnt_player++; + if (game->map[y][x] == 'E') + check->qnt_exit++; + if (game->map[y][x] == 'C') + check->qnt_collectibles++; + x++; + } + y++; + } +}