-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_two.c
More file actions
77 lines (69 loc) · 2.16 KB
/
helper_two.c
File metadata and controls
77 lines (69 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* helper_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: andcardo <andcardo@student.42lisboa.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/27 13:32:14 by andcardo #+# #+# */
/* Updated: 2025/11/27 14:59:28 by andcardo ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void flood_fill(char **grid, t_game *game, int x, int y)
{
if (x < 0 || y < 0 || x >= game->width || y >= game->height)
return ;
if (grid[y][x] == 'X' || grid[y][x] == '1')
return ;
grid[y][x] = 'X';
flood_fill(grid, game, x + 1, y);
flood_fill(grid, game, x - 1, y);
flood_fill(grid, game, x, y + 1);
flood_fill(grid, game, x, y - 1);
}
void update_player_position(t_game *game, int x, int y)
{
game->player_x = x;
game->player_y = y;
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len_s1;
size_t len_s2;
size_t total_size;
char *concat_str;
if (!s1 || !s2)
return (NULL);
len_s1 = ft_strlen(s1);
len_s2 = ft_strlen(s2);
total_size = len_s1 + len_s2;
concat_str = (char *)malloc(sizeof(char) * (total_size + 1));
if (!concat_str)
return (NULL);
ft_memcpy(concat_str, s1, len_s1);
ft_memcpy(concat_str + len_s1, s2, len_s2);
concat_str[total_size] = '\0';
return (concat_str);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *dest_ptr;
const unsigned char *src_ptr;
if (!dest && !src)
return (dest);
dest_ptr = dest;
src_ptr = src;
while (n--)
{
*dest_ptr = *src_ptr;
dest_ptr++;
src_ptr++;
}
return (dest);
}
void print_to_fd(char *str, int fd)
{
if (write(fd, str, ft_strlen(str)) == -1)
return ;
}