-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_utils.c
88 lines (79 loc) · 1.97 KB
/
errors_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abertran <abertran@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/25 14:08:25 by abertran #+# #+# */
/* Updated: 2023/04/26 18:57:39 by abertran ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void check_rectangle(t_start *game)
{
int i;
int w;
i = 1;
game->mapwidth = get_width(game->map[0]);
while (game->map[i])
{
w = get_width(game->map[i]);
if (w != game->mapwidth)
{
printf("Error: Width not the same in all lines\n");
exit_game(game);
}
game->mapwidth = get_width(game->map[i]);
i++;
}
}
void copy_map(char **map, t_start *game)
{
int i;
int j;
i = -1;
while (++i < game->mapheight)
map[i] = (char *)malloc(sizeof(char) * game->mapwidth);
i = 0;
while (i < game->mapheight)
{
j = 0;
while (j < game->mapwidth)
{
map[i][j] = game->map[i][j];
j++;
}
i++;
}
}
void valid_map(char *map, char *ext)
{
int i;
int j;
i = ft_strlen(map) - ft_strlen(ext);
j = 0;
while (map[i + j] && ext[j])
{
if (map[i + j] == ext[j])
j++;
else
{
printf("Error: The map has to be a .ber file\n");
exit(1);
}
}
}
void *valid_xpm(t_start *game, char *str)
{
void *img;
int px;
px = 45;
img = mlx_xpm_file_to_image(game->mlx, str, &px, &px);
if (!img)
{
printf("Error: .xpm issue\n");
exit_game(game);
}
return (img);
}