-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_tetri.c
113 lines (102 loc) · 2.1 KB
/
move_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_tetri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: phanna <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/21 11:15:01 by phanna #+# #+# */
/* Updated: 2017/07/26 14:18:49 by phanna ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
char **move_up(int y_min, char **tab)
{
int i;
i = 0;
while (i + y_min < 4)
{
tab[i] = tab[i + y_min];
++i;
}
while (i < 4 && y_min > 0)
{
tab[i] = "....\0";
++i;
}
return (tab);
}
char **move_left(int x_min, char **tab)
{
int tmp;
int i;
int j;
tmp = 0;
i = -1;
j = 0;
while (++i < 4)
{
while (tab[i][j + x_min] != '\0')
{
tab[i][j] = tab[i][j + x_min];
j++;
}
tmp = x_min;
while (tmp > 0 && tmp > 0)
{
tab[i][4 - tmp] = '.';
tmp--;
}
j = 0;
}
return (tab);
}
int get_y_min(char **tab)
{
int x;
int y;
int y_min;
x = -1;
y = 0;
y_min = 0;
while (++x < 4)
{
while (tab[x][y] != '#' && tab[x][y] != '\0')
y++;
if (y == 4)
y_min++;
else
return (y_min);
y = 0;
}
return (y_min);
}
int get_x_min(char **tab)
{
int x;
int y;
int x_min;
x = -1;
y = 0;
x_min = 4;
while (++x < 4)
{
while (tab[x][y] != '#' && tab[x][y] != '\0')
y++;
x_min = (y < x_min) ? y : x_min;
y = 0;
}
return (x_min);
}
t_tetri *move_tetri(t_tetri *first)
{
t_tetri *tmp;
tmp = first;
while (tmp)
{
tmp->tetri = move_left(get_x_min(tmp->tetri), tmp->tetri);
tmp->tetri = move_up(get_y_min(tmp->tetri), tmp->tetri);
tmp = tmp->next;
}
return (first);
}