-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_errors_map.c
135 lines (126 loc) · 2.35 KB
/
check_errors_map.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
132
133
134
135
#include "cub3d.h"
void check_errors_map(char **save, int size)
{
if (check_close(save, size) == -1)
{
printf("ERROR = MAP IS NOT CLOSE! CHANGE IT SO PLAYER CAN NOT ESCAPE!");
exit(0);
}
if (check_outside(save, size) == -1)
{
printf("ERROR = THERE IS A ERROR! CHANGE IT SO PLAYER CAN NOT ESCAPE!");
exit(0);
}
if (check_inside(save, size) == -1)
{
printf("ERROR = SOMETHING WRONG IN MAP. CORRECT IT (please)");
exit(0);
}
if (check_letters(save, size) != 1)
{
printf("ERROR = NO PLAYER OR MORE THAN ONE PLAYER. CHANGE IT.");
exit(0);
}
}
int check_outside(char **save, int size)
{
int x;
int y;
int empty;
int first;
x = 0;
first = start_map(save);
empty = counter_map(save, first, size) + 1;
while (x < size)
{
y = 0;
while (y < ft_strlen(save[x]))
{
if (help_checker(save, x, y, first) == -1)
return (-1);
if (x == size - empty || (y + 1 == ft_strlen(save[x])))
{
if ((ft_iswall(save[x][y]) == 0))
return (-1);
}
y++;
}
x++;
}
return (0);
}
int check_inside(char **save, int size)
{
int x;
int y;
int first;
first = start_map(save);
x = first + 1;
while (x < (size - counter_map(save, first, size)))
{
y = 1;
while (y < ft_strlen(save[x]))
{
while (save[x][y] == ' ')
y++;
if (save[x][y] != '0' && save[x][y] != '1' && save[x][y] != '2'
&& save[x][y] != 'N' && save[x][y] != 'S'
&& save[x][y] != 'W' && save[x][y] != 'E')
return (-1);
y++;
}
x++;
}
return (0);
}
int check_letters(char **save, int size)
{
int x;
int y;
int counter;
int first;
first = start_map(save);
x = first + 1;
counter = 0;
while (x < (size - counter_map(save, first, size)))
{
y = 1;
while (y < ft_strlen(save[x]))
{
while (save[x][y] == ' ')
y++;
if (save[x][y] == 'N' || save[x][y] == 'S'
|| save[x][y] == 'W' || save[x][y] == 'E')
counter++;
y++;
}
x++;
}
return (counter);
}
int check_close(char **save, int size)
{
int x;
int y;
int first;
first = start_map(save);
x = first + 1;
while (x < (size - (counter_map(save, first, size) + 1)))
{
y = 1;
while (y < ft_strlen(save[x]))
{
while (save[x][y] == ' ')
y++;
if (check_other_things(save, x, y) == -1)
return (-1);
if (check_what_it_is(save, x, y, 1) == -1)
return (-1);
if (check_what_it_is(save, x, y, 2) == -1)
return (-1);
y++;
}
x++;
}
return (0);
}