-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_map.c
68 lines (61 loc) · 1.62 KB
/
create_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tduval <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 04:28:22 by pvandamm #+# #+# */
/* Updated: 2018/11/21 14:22:44 by pvandamm ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void print_map(char **map)
{
int i;
i = 0;
while (map[i])
ft_putendl(map[i++]);
}
char **init_map(int size)
{
char **new;
int j;
int i;
j = 0;
i = 0;
if (!(new = (char **)malloc(sizeof(char *) * (size) + 1)))
return (0);
new[size] = 0;
while (j < size)
{
if (!(new[j] = (char *)malloc(sizeof(char) * (size) + 1)))
return (0);
new[j][size] = 0;
j++;
}
while (new[i])
{
j = 0;
while (j < size)
new[i][j++] = '.';
i++;
}
return (new);
}
char **create_map(char ***tetri, char **map)
{
int size;
int i;
i = 0;
size = count_size(tetri);
while (tetri[i])
{
if (get_bot(tetri, i) > size)
size = get_bot(tetri, i) + 1;
i++;
}
if (!(map = init_map(size)))
return (0);
return (map);
}