Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathalia Vitoria Buchholz committed Feb 7, 2025
1 parent 29bae32 commit 736c7f6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -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 $@
Expand Down
10 changes: 6 additions & 4 deletions includes/so_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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

24 changes: 17 additions & 7 deletions src/game_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
Expand All @@ -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)
{

}
6 changes: 3 additions & 3 deletions src/get_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/so_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
}
25 changes: 21 additions & 4 deletions src/utils_validation_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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);
}

Expand Down
38 changes: 26 additions & 12 deletions src/validate_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nbuchhol <nbuchhol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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++;
}
}

0 comments on commit 736c7f6

Please sign in to comment.