-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsing_utils.c
More file actions
121 lines (112 loc) · 2.49 KB
/
parsing_utils.c
File metadata and controls
121 lines (112 loc) · 2.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aylaaouf <aylaaouf@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/10 02:56:28 by aylaaouf #+# #+# */
/* Updated: 2025/03/20 02:16:39 by aylaaouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void invalid_char(t_game *game)
{
int i;
int j;
i = 0;
while (game->map->map[i])
{
j = 0;
while (game->map->map[i][j])
{
if (game->map->map[i][j] != 'C' && game->map->map[i][j] != 'E' &&
game->map->map[i][j] != 'P' && game->map->map[i][j] != '1' &&
game->map->map[i][j] != '0' && game->map->map[i][j] != 'X')
{
ft_printf("Error: Invalid Character in map\n");
free_map(game->map);
clean_game(game);
exit(0);
}
j++;
}
i++;
}
}
void get_size_width_height(char **map, int *height, int *width)
{
*height = 0;
*width = 0;
while (map[*height])
(*height)++;
while (map[0][*width])
(*width)++;
}
int count_lines(char *filename)
{
int count;
char *line;
int fd;
fd = open(filename, O_RDONLY);
if (fd < 0)
{
ft_printf("Error: Wrong path");
return (-1);
}
line = get_next_line(fd);
count = 0;
while (line)
{
count++;
free(line);
line = get_next_line(fd);
}
close(fd);
return (count);
}
int is_exist(t_map *map)
{
t_var var;
int i, (j);
if (!map || !map->map)
return (0);
i = 0;
var.player = 0;
var.exit = 0;
var.coins = 0;
while (map->map[i])
{
j = 0;
while (map->map[i][j])
{
if (map->map[i][j] == 'P')
var.player++;
if (map->map[i][j] == 'E')
var.exit++;
if (map->map[i][j] == 'C')
var.coins++;
j++;
}
i++;
}
return (var.player == 1 && var.exit == 1 && var.coins > 0);
}
int find_enemy_before(t_game *game)
{
int y, (x);
y = 0;
x = 0;
while (game->map->map[y])
{
x = 0;
while (game->map->map[y][x])
{
if (game->map->map[y][x] == 'X')
return (1);
x++;
}
y++;
}
return (0);
}