-
Notifications
You must be signed in to change notification settings - Fork 0
/
valid_2.c
95 lines (86 loc) · 1.58 KB
/
valid_2.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
#include "header/so_long.h"
void ft_is_ber(char **argv)
{
int i;
i = ft_strlen(argv[1]);
if ((argv[1][i - 4] != '.') || (argv[1][i - 3] != 'b')
|| (argv[1][i - 2] != 'e') || (argv[1][i - 1] != 'r'))
ft_print_error("Wrong map format");
}
void ft_is_correct(t_Mapinfo *map_info)
{
int i;
int j;
int exit;
int start;
j = -1;
exit = 0;
start = 0;
while (++j < map_info->width)
{
i = -1;
while (++i < map_info->length)
{
if (map_info->map[j][i] == 'E')
exit += 1;
if (map_info->map[j][i] == 'P')
start += 1;
if (map_info->map[j][i] == 'C')
map_info->items += 1;
}
}
if ((exit == 0) || (start == 0) || (map_info->items == 0))
ft_print_error("Wrong positions");
}
int ft_find_player(t_Mapinfo *map_info, t_Image *img)
{
int i;
int j;
j = -1;
while (++j < map_info->width)
{
i = -1;
while (++i < map_info->length)
{
if (map_info->map[j][i] == 'P')
{
img->player_x = i;
img->player_y = j;
return (0);
}
}
}
return (0);
}
int ft_find_enemy(t_Mapinfo *map_info, t_Image *img)
{
int i;
int j;
j = -1;
while (++j < map_info->width)
{
i = -1;
while (++i < map_info->length)
{
if (map_info->map[j][i] == 'C')
{
img->enemy_x = i;
img->enemy_y = j;
return (0);
}
}
}
return (0);
}
void ft_create_and_check_map(char **argv, t_Mapinfo *map_info, t_Image *img)
{
ft_init_struct(map_info, img);
ft_is_ber(argv);
ft_parse_map(argv, map_info);
ft_is_rect(map_info);
ft_is_fenced(map_info);
ft_is_valid(map_info);
ft_is_correct(map_info);
ft_find_player(map_info, img);
ft_find_enemy(map_info, img);
}