-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_map.c
73 lines (66 loc) · 2.1 KB
/
check_map.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ekraujin <ekraujin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/21 18:04:24 by ekraujin #+# #+# */
/* Updated: 2022/04/11 01:17:04 by ekraujin ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int check_top_n_bot(t_data *game, int line)
{
int i;
i = 0;
while (game->map[line][i] && game->map[line][i] != '\n')
{
if (game->map[line][i] != '1' && game->map[line][i] != ' ')
return (0);
i++;
}
return (1);
}
static int line_check(t_data *game, int line)
{
int i;
i = 0;
if (game->map[line][i] != ' ' && game->map[line][i] != '1')
return (0);
i = 1;
while (game->map[line][i] && game->map[line][i] != '\n')
{
if (game->map[line][i] == ' ' && game->map[line][i] != ' ' \
&& game->map[line][i] != '1')
return (0);
while (game->map[line][i] == ' ')
i++;
if (game->map[line][i - 1] == ' ' && game->map[line][i] != '1')
return (0);
if (game->map[line][i] == '0' && \
((game->map[line - 1][i] != '1' && game->map[line - 1][i] != '0') \
|| (game->map[line + 1][i] != '1' && game->map[line + 1][i] != '0')))
return (0);
i++;
}
if (game->map[line][i - 1] != ' ' && game->map[line][i - 1] != '1')
return (0);
return (1);
}
int check_map(t_data *game)
{
int i;
i = 0;
if (!check_top_n_bot(game, i))
return (0);
i = 1;
while (i < game->lc)
{
if (!line_check(game, i))
return (0);
i++;
}
game->map[(int)game->ppos_y][(int)game->ppos_x] = game->pdir;
return (1);
}