-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_map_2.c
More file actions
122 lines (112 loc) · 2.89 KB
/
Copy pathparse_map_2.c
File metadata and controls
122 lines (112 loc) · 2.89 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_map_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: devoma <devoma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 12:17:39 by devoma #+# #+# */
/* Updated: 2023/05/18 18:28:40 by devoma ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_full_map(char **map)
{
int i;
int count;
int count_2;
i = -1;
count = 0;
count_2 = 0;
if (check_full_map_2(map, i, count, count_2) == 0)
return (0);
return (1);
}
int check_full_map_2(char **map, int i, int count, int count_2)
{
int j;
while (map[++i] && count < 6)
{
j = 0;
if (is_id(map[i], j))
{
count++;
count_2 += is_id(map[i], j);
}
else
{
while (map[i][j])
{
if (map[i][j] != '1' && map[i][j] != '0' && map[i][j] != ' '
&& map[i][j] != '\t' && map[i][j] != '\n' && map[i][j] != 'N'
&& map[i][j] != 'S' && map[i][j] != 'E' && map[i][j] != 'W')
return (0);
j++;
}
}
}
if (count_2 != 21 || check_full_map_3(map, i) == 0)
return (0);
return (1);
}
int check_full_map_3(char **map, int i)
{
int first_i;
int last_i;
first_i = i;
while (map[++i])
last_i = i;
if (check_walls(map, first_i, last_i) == 0
|| check_all_chars(map, first_i) == 0
|| check_elem_count(map, first_i) == 0)
return (0);
return (1);
}
int is_id(char *map_line, int j)
{
char *new_line;
while (map_line[j] && (map_line[j] == ' ' || map_line[j] == '\t'))
j++;
if (map_line[j] && (map_line[j] == 'F' || map_line[j] == 'C'))
return (is_id_3(map_line, j));
else if ((map_line[j] == 'N' && map_line[j + 1] && map_line[j + 1] == 'O')
|| (map_line[j] == 'S' && map_line[j + 1] && map_line[j + 1] == 'O')
|| (map_line[j] == 'W' && map_line[j + 1] && map_line[j + 1] == 'E')
|| (map_line[j] == 'E' && map_line[j + 1] && map_line[j + 1] == 'A'))
{
new_line = create_line(map_line, j);
if (!new_line || check_textures(new_line) == 0)
{
free(new_line);
return (0);
}
else
return (is_id_2(map_line, j, new_line));
}
return (0);
}
int is_id_2(char *map_line, int j, char *new_line)
{
if (map_line[j] == 'N')
{
free(new_line);
return (3);
}
else if (map_line[j] == 'S')
{
free(new_line);
return (4);
}
else if (map_line[j] == 'W')
{
free(new_line);
return (5);
}
else
{
free(new_line);
return (6);
}
free(new_line);
return (0);
}