-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetri.c
executable file
·76 lines (68 loc) · 1.76 KB
/
tetri.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tetri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 11:45:46 by staeter #+# #+# */
/* Updated: 2019/01/12 14:16:39 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void free_tetri(t_tetri **te)
{
free(*te);
*te = NULL;
}
t_tetri *new_tetri(void)
{
t_tetri *dest;
short i;
if (!(dest = (t_tetri *)malloc(sizeof(t_tetri))))
return (NULL);
dest->letter = '\0';
dest->ising = 0;
i = 0;
while (i < 16)
dest->tab[i++] = 0;
return (dest);
}
t_boolean fill_tetri(t_tetri *te, char **str, char letter)
{
unsigned short i;
unsigned short j;
te->letter = letter;
i = 0;
while (i < 4)
{
j = 0;
while (j < 4)
{
if (**str == '#')
te->tab[i] |= (1 << j);
else if (**str == '.')
te->tab[i] |= (0 << j);
else
return (0);
(*str)++;
j++;
}
if (**str != '\n')
return (0);
(*str)++;
i++;
}
return (1);
}
t_tetri *fillnew_tetri(char **str, char letter)
{
t_tetri *dest;
if (!(dest = new_tetri())
|| !fill_tetri(dest, str, letter))
{
free_tetri(&dest);
return (NULL);
}
return (dest);
}