-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.c
93 lines (84 loc) · 1.85 KB
/
printer.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gboudrie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/14 18:32:19 by gboudrie #+# #+# */
/* Updated: 2016/01/19 18:04:49 by gboudrie ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static char **tabnew(int size)
{
char **tab;
int i;
if (!(tab = (char **)ft_memalloc(sizeof(*tab) * size)))
return (NULL);
i = 0;
while (i < size)
{
if (!(tab[i] = ft_strnew(size)))
return (NULL);
i++;
}
tab[i] = NULL;
return (tab);
}
static char **dot_filler(char **tab, int size)
{
int i;
int j;
i = 0;
while (i < size)
{
j = 0;
while (j < size)
{
tab[i][j] = '.';
j++;
}
i++;
}
return (tab);
}
static void free_tab(char **tab, int size)
{
int i;
i = 0;
while (i < size)
{
ft_putendl(tab[i]);
ft_strdel(&tab[i]);
i++;
}
ft_memdel((void **)tab);
}
void printer(t_tetr *ptr, int size)
{
int i;
int j;
char **tab;
tab = tabnew(size);
dot_filler(tab, size);
while (ptr != NULL)
{
i = 0;
while (i < 4)
{
j = 0;
while (j < 4)
{
if (ptr->tetrimino[i][j] == '#')
{
tab[ptr->x + i][ptr->y + j] = ptr->nbr;
}
j++;
}
i++;
}
ptr = ptr->next;
}
free_tab(tab, size);
}