-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_map.c
More file actions
130 lines (120 loc) · 2.7 KB
/
Copy pathcheck_map.c
File metadata and controls
130 lines (120 loc) · 2.7 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
123
124
125
126
127
128
129
130
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbertin <mbertin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/11 10:52:14 by mbertin #+# #+# */
/* Updated: 2022/09/06 08:42:30 by mbertin ### ########.fr */
/* */
/* ************************************************************************** */
#include "include/so_long.h"
void size_map_vertical(t_map *map)
{
char *temp;
map->x = 0;
temp = get_next_line(map->fd);
while (temp != NULL)
{
free(temp);
temp = get_next_line(map->fd);
map->x++;
}
free(temp);
if (map->x <= 2)
{
printf("Error\nThe map is to small\n");
exit (1);
}
}
void print_map(t_map *map)
{
map->map = malloc(sizeof(char **) * map->x + 1);
if (!map->map)
exit (1);
map->x = 0;
map->map[map->x] = get_next_line(map->fd);
while (1)
{
map->x++;
map->map[map->x] = get_next_line(map->fd);
if (map->map[map->x] == NULL)
break ;
}
printf("\n");
}
void check_rectangle(t_map *map)
{
int i;
size_t first_line;
i = 1;
first_line = ft_strlen(map->map[0]);
while (map->map[i] != NULL)
{
if (first_line != ft_strlen(map->map[i]) && i != (map->x - 1))
{
printf("Error\nMap is not rectangular\n");
exit (0);
}
if (i == (map->x - 1))
{
if ((first_line - 1) != ft_strlen(map->map[i]))
{
printf("Error\nMap is not rectangular\n");
exit (0);
}
}
i++;
}
}
void check_wall_horizontal(t_map *map)
{
size_t i;
i = 0;
while (i < (ft_strlen(map->map[0]) - 1))
{
if (map->map[0][i] != '1')
{
printf("Error\nA 1 is missing in the top wall\n");
exit (0);
}
i++;
}
i = 0;
while (i < ft_strlen(map->map[map->x - 1]))
{
if (map->map[map->x - 1][i] != '1')
{
printf("Error\nA 1 is missing in the bottom wall\n");
exit (0);
}
i++;
}
}
void check_wall_vertical(t_map *map)
{
int i;
int first_lane;
i = 0;
first_lane = ft_strlen(map->map[0]);
while (i < map->x - 1)
{
if (map->map[i][0] != '1')
{
printf("Error\nA 1 is missing in the left wall\n");
exit (0);
}
i++;
}
i = 0;
while (i < map->x - 1)
{
if (map->map[i][first_lane - 2] != '1')
{
printf("Error\nA 1 is missing in the right wall\n");
exit (0);
}
i++;
}
}