-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.c
109 lines (100 loc) · 2.57 KB
/
check.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ofadhel <ofadhel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/22 17:27:31 by ofadhel #+# #+# */
/* Updated: 2023/04/24 22:22:39 by ofadhel ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
void free_map_check(t_check *check)
{
int i;
i = 0;
while (check->map[i])
{
free(check->map[i]);
i++;
}
free(check->map);
}
void checks(t_check *check, t_game *game)
{
if (check_walls(check, check->map_height, check->map_width) == 0)
{
ft_printf("ERROR, map walls\n");
free_map(game);
free_map_check(check);
exit(1);
}
check_map(check, game);
if (check->player != 1 || check->coin == 0 || check->exit != 1)
{
ft_printf("ERROR, map\n");
free_map(game);
free_map_check(check);
exit(1);
}
free_map_check(check);
}
int check_walls(t_check *check, int height, int width)
{
int i;
i = 0;
while (check->map[0][i])
{
if (check->map[0][i] != '1' || check->map[height - 1][i] != '1')
{
return (0);
}
i++;
}
i = 0;
while (check->map[i])
{
if (check->map[i][0] != '1' || check->map[i][width - 1] != '1')
{
return (0);
}
i++;
}
return (1);
}
void check_map(t_check *check, t_game *game)
{
int height;
int width;
height = 0;
while (game->map[height])
{
width = 0;
while (game->map[height][width])
{
count_sprites(check, game, height, width);
width++;
}
height++;
}
}
void count_sprites(t_check *check, t_game *game, int height, int width)
{
if (check->map[height][width] == '0')
return ;
else if (check->map[height][width] == '1')
return ;
else if (check->map[height][width] == 'P')
check->player++;
else if (check->map[height][width] == 'C')
{
game->coin_count++;
check->coin++;
}
else if (check->map[height][width] == 'E')
check->exit++;
else if (check->map[height][width] == 'N')
return ;
return ;
}