-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_maps.c
More file actions
111 lines (103 loc) · 2.62 KB
/
Copy pathcheck_maps.c
File metadata and controls
111 lines (103 loc) · 2.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_maps.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cerdelen <cerdelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/07 17:26:07 by cerdelen #+# #+# */
/* Updated: 2022/03/07 17:27:31 by cerdelen ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void check_rectangular_shape(char **map, int rows, int columns)
{
int i;
int j;
char check;
i = 0;
while (i < (rows - 1))
{
j = ft_strlen(map[i]);
map[i][j - 1] = 0;
i++;
if (j != (columns + 2))
non_rectangular_map();
}
j = ft_strlen(map[i]);
if (j != columns)
non_rectangular_map();
}
void check_amount_of_extra_fields(int *different_tiles)
{
if (different_tiles[0] == 0)
{
write(2, "There is no starting Position for the Player!\n", 46);
exit(EXIT_SUCCESS);
}
if (different_tiles[0] > 1)
{
write(2, "There are more than one starting Positions for the Player!\n",
59);
exit(EXIT_SUCCESS);
}
if (different_tiles[1] == 0)
{
write(2, "There is no map exit!\n", 22);
exit(EXIT_SUCCESS);
}
if (different_tiles[2] < 1)
{
write(2, "There is no collectible on the Map!\n", 36);
exit(EXIT_SUCCESS);
}
}
void check_all_necessities(char **map, int rows, int columns)
{
int different_tiles[3];
int i;
int j;
i = 0;
different_tiles[0] = 0;
different_tiles[1] = 0;
different_tiles[2] = 0;
while (i < rows)
{
j = 0;
while (j < columns)
{
if (map[i][j] == 'P')
different_tiles[0]++;
else if (map[i][j] == 'E')
different_tiles[1]++;
else if (map[i][j] == 'C')
different_tiles[2]++;
j++;
}
i++;
}
check_amount_of_extra_fields(different_tiles);
}
void check_validity(char **map, int rows, int columns)
{
int i;
int j;
i = 0;
check_rectangular_shape(map, rows, columns);
while (i < rows)
{
j = 0;
while (j < columns)
{
if (i == 0 || i == rows - 1)
no_surrounding_wall(map[i][j]);
else if (j == 0 || j == columns - 1)
no_surrounding_wall(map[i][j]);
else
check_interior(map[i][j]);
j++;
}
i++;
}
check_all_necessities(map, rows, columns);
}