-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflood.c
More file actions
122 lines (111 loc) · 2.49 KB
/
Copy pathflood.c
File metadata and controls
122 lines (111 loc) · 2.49 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flood.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rahidalg <rahidalg@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/23 10:30:32 by rahidalg #+# #+# */
/* Updated: 2025/01/23 10:30:51 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void close_map_rows(char **map)
{
int i;
int j;
i = 0;
j = 0;
while (map[i])
{
while (map[i][j] && map[i][j] != '\n')
{
j++;
}
map[i][j] = '\0';
j = 0;
i++;
}
}
void get_player(char **map, t_mlx_data *data)
{
int i;
int j;
i = 0;
j = 0;
while (map[i])
{
while (map[i][j])
{
if (map[i][j] == 'P')
{
data->player_x = j;
data->player_y = i;
}
else if (map[i][j] == 'C')
data->coins++;
j++;
}
j = 0;
i++;
}
}
void debbug_map(char **map)
{
int i;
int j;
i = 0;
j = 0;
while (map[i])
{
while (map[i][j])
{
ft_printf("%c", map[i][j]);
j++;
}
ft_printf("\n");
j = 0;
i++;
}
}
int boundary_fill(t_mlx_data *data, char **map, int x, int y)
{
int up;
int down;
int right;
int left;
if (y < 0 || y >= data->game.win.height || x < 0
|| x >= data->game.win.width || map[y][x] == '1')
return (0);
if (map[y][x] == 'C')
data->counter++;
if (map[y][x] == 'E')
data->is_exit++;
map[y][x] = '1';
up = boundary_fill(data, map, x, y - 1);
down = boundary_fill(data, map, x, y + 1);
right = boundary_fill(data, map, x + 1, y);
left = boundary_fill(data, map, x - 1, y);
if (up || down || left || right)
return (1);
else
return (0);
}
void read_map(int fd, char **map, t_mlx_data *data)
{
int i;
char *line;
i = 0;
line = get_next_line(fd);
while (i < data->game.win.height)
{
alloc_map(map, line, i);
ft_strlcpy(map[i], line, (ft_strlen(line) + 1));
line = read_next_line(fd, line);
i++;
}
map[i] = NULL;
close_map_rows(map);
get_player(map, data);
boundary_fill(data, map, data->player_x, data->player_y);
}