-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetri.c
83 lines (73 loc) · 2.01 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
77
78
79
80
81
82
83
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tetri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kfonda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/28 01:37:07 by kfonda #+# #+# */
/* Updated: 2018/11/28 01:37:11 by kfonda ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** 3(now size) because that is the max coordinate they can have within their 4*4
** tetramino map, but this function it's used also in the map so has to be size
*/
int move_topleft(char (*tet_coord)[5][2], int size)
{
int min_x;
int min_y;
int c;
min_x = size;
min_y = size;
c = 0;
while (c < 4)
{
if (min_x > (*tet_coord)[c][0])
min_x = (*tet_coord)[c][0];
if (min_y > (*tet_coord)[c][1])
min_y = (*tet_coord)[c][1];
c++;
}
c = 0;
while (c < 4)
{
(*tet_coord)[c][0] = (*tet_coord)[c][0] - min_x;
(*tet_coord)[c][1] = (*tet_coord)[c][1] - min_y;
c++;
}
return (1);
}
void ft_movetetriright(char (*tetri)[5][2])
{
int i;
i = -1;
while (++i < 4)
(*tetri)[i][0]++;
}
void ft_movetetridown(char (*tet_coord)[5][2], int size)
{
int c;
int min_x;
min_x = size;
c = -1;
while (++c < 4)
{
if (min_x > (*tet_coord)[c][0])
min_x = (*tet_coord)[c][0];
}
c = -1;
while (++c < 4)
{
(*tet_coord)[c][0] -= min_x;
(*tet_coord)[c][1]++;
}
}
void ft_cleantetri(char ***map, char (*tetri)[5][2])
{
int i;
i = -1;
while (++i < 4)
(*map)[(int)(*tetri)[i][1]][(int)(*tetri)[i][0]] = '.';
}