-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_rotated.c
95 lines (88 loc) · 1.95 KB
/
set_rotated.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
/*
** set_rotated.c for tetris in /home/rectoria/delivery/Projets/PSU_2016_tetris
**
** Made by Bastien
** Login <[email protected]>
**
** Started on Thu Feb 23 21:45:45 2017 Bastien
** Last update Fri Mar 17 12:46:20 2017 Thibaut Cornolti
*/
#include <stdlib.h>
#include "tetris.h"
void rotate_down(t_shapes *piece)
{
int i;
int j;
int k;
int v;
i = -1;
k = piece->height;
if ((piece->map_down = malloc(sizeof(char *) *
(piece->height + 1))) == NULL)
return ;
piece->map_down[k] = NULL;
while (--k >= 0 && piece->map[k])
{
j = piece->width;
v = -1;
if ((piece->map_down[++i] = malloc(sizeof(char) *
(piece->width + 1))) == NULL)
return ;
while (--j >= 0)
piece->map_down[i][++v] = piece->map[k][j];
piece->map_down[i][++v] = '\0';
}
}
void rotate_left(t_shapes *piece)
{
int j;
int k;
int v;
int w;
k = piece->width;
v = 0;
if ((piece->map_left = malloc(sizeof(char *) *
(piece->width + 1))) == NULL)
return ;
piece->map_left[piece->width] = NULL;
while (--k >= 0)
{
j = -1;
w = -1;
if ((piece->map_left[v] = malloc(sizeof(char) *
(piece->height + 1))) == NULL)
return ;
piece->map_left[v][piece->height] = '\0';
while (++j < piece->height)
piece->map_left[v][++w] = piece->map[j][k];
v++;
}
rotate_down(piece);
}
void rotate_right(t_shapes *piece)
{
int j;
int k;
int v;
int w;
k = -1;
v = 0;
if (piece->map == NULL)
return ;
if ((piece->map_right = malloc(sizeof(char *) *
(piece->width + 1))) == NULL)
return ;
piece->map_right[piece->width] = NULL;
while (++k < piece->width)
{
j = -1;
w = piece->height;
if ((piece->map_right[v] = malloc((piece->height + 1))) == NULL)
return ;
piece->map_right[v][piece->height] = '\0';
while (++j < piece->height)
piece->map_right[v][--w] = piece->map[j][k];
v++;
}
rotate_left(piece);
}