-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_utils.c
More file actions
92 lines (84 loc) · 2.28 KB
/
map_utils.c
File metadata and controls
92 lines (84 loc) · 2.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rahidalg <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/27 12:30:16 by rahidalg #+# #+# */
/* Updated: 2024/12/27 13:08:38 by rahidalg ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
char *read_next_line(int fd, char *line)
{
free(line);
return (get_next_line(fd));
}
int chars_checker(char *dir, t_mlx_data *data)
{
char *line;
int i;
int ch_error;
int fd;
i = 0;
ch_error = 1;
fd = get_file(dir, data);
line = get_next_line(fd);
while (line != NULL)
{
while (line[i] != '\n' && line[i] != '\0')
{
if (ch_error && (line[i] != '0' && line[i] != '1' && line[i] != 'C'
&& line[i] != 'E' && line[i] != 'P'))
ch_error = 0;
i++;
}
i = 0;
line = read_next_line(fd, line);
}
if (!ch_error)
ft_printf("Error\nThe map have unknown characters!\n");
return (ch_error);
}
int map_checker(int fd, int player_count, int coin_count, int door_count)
{
char *line;
int i;
i = 0;
line = get_next_line(fd);
while (line != NULL)
{
while (line[i] != '\n' && line[i] != '\0')
{
i++;
if (line[i] == 'P')
player_count += 1;
else if (line[i] == 'C')
coin_count += 1;
else if (line[i] == 'E')
door_count += 1;
}
i = 0;
line = read_next_line(fd, line);
}
if (!map_handler(player_count, coin_count, door_count))
return (0);
return (1);
}
int map_position(t_map_data *map, char id, int pos_x, int pos_y)
{
map->id = id;
map->pos_x = pos_x;
map->pos_y = pos_y;
return (1);
}
void check_size_error(int error, t_mlx_data *data)
{
if (error == 1)
{
ft_printf("Error\nThe map is not rectangular!\n");
close_mlx(data);
exit (1);
}
}