-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_map_1.c
131 lines (122 loc) · 2.58 KB
/
check_map_1.c
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
131
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_map_1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dyoula <dyoula@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/10 18:42:01 by dyoula #+# #+# */
/* Updated: 2022/01/27 19:05:01 by dyoula ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int walls(char **map, int max)
{
int i;
int size;
int j;
size = ft_strlen(map[0]);
i = -1;
while (map[++i])
{
if ((int)ft_strlen(map[i]) != size)
return (-1);
if (i == 0 || i == max - 1)
{
j = -1;
while (map[i][++j])
if (map[i][j] != '1')
return (-2);
}
if ((map[i][0] != '1' || map[i][size - 1] != '1'))
return (-3);
}
return (1);
}
int error_messages_parser(int n)
{
if (n == -1)
{
ft_putstr_fd("wrong size\n", 2);
return (0);
}
else if (n == -2)
{
ft_putstr_fd("error\n Missing wall in floor or roof ?\n", 2);
return (0);
}
else if (n == -3)
{
ft_putstr_fd("wall_missing", 2);
return (0);
}
else
return (1);
}
int error_messages_game(int tab[3], t_vars *g)
{
if (tab[0] != 1)
{
ft_putstr_fd("error\nOnly one player accepted\n", 2);
free_d_tab(g->map);
free(g->map);
exit(0);
}
else if (tab[1] < 1)
{
ft_putstr_fd("error\nNo Collectibles\n", 2);
free_d_tab(g->map);
free(g->map);
exit(0);
}
else if (tab[2] < 1)
{
ft_putstr_fd("error\nNo exit\n", 2);
free_d_tab(g->map);
free(g->map);
exit(0);
}
return (1);
}
int right_number_pce(char **map, t_vars *g)
{
int i;
int j;
int tab[3];
i = -1;
tab[0] = 0;
tab[1] = 0;
tab[2] = 0;
while (map[++i])
{
j = -1;
while (map[i][++j])
{
if (map[i][j] == 'P')
tab[0]++;
else if (map[i][j] == 'C')
tab[1]++;
else if (map[i][j] == 'E')
tab[2]++;
else if (map[i][j] != '1' && map[i][j] != '0')
return (0);
}
}
return (error_messages_game(tab, g));
}
int forbidden_caracters(char **map)
{
int i;
int j;
i = -1;
while (map[++i])
{
j = -1;
while (map[i][++j])
{
if (!is_part(map[i][j]))
return (0);
}
}
return (1);
}