Merge branch 'develop' of https://github.com/ykolomiets/fillit into develop
This commit is contained in:
commit
0b4a9b9d5b
2 changed files with 60 additions and 0 deletions
43
fillit.c
Normal file
43
fillit.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "fillit.h"
|
||||
|
||||
unsigned int ft_sqrt_ceil(unsigned int num)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
while (i * i < num)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
void clear_map(t_map *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < 16)
|
||||
map->line[i++] = 0;
|
||||
}
|
||||
|
||||
t_tetraminos *convert_tetramino(char *s)
|
||||
{
|
||||
t_tetraminos *res;
|
||||
|
||||
res = (t_tetraminos*)malloc(sizeof(t_tetraminos));
|
||||
return (res);
|
||||
}
|
||||
|
||||
t_map *map_initialization(char **tetramino_table)
|
||||
{
|
||||
t_map *map;
|
||||
unsigned int i;
|
||||
|
||||
map = (t_map*)malloc(sizeof(t_map));
|
||||
i = 0;
|
||||
while (*tetramino_table)
|
||||
map->figure[i++] = convert_tetramino(*tetramino_table++);
|
||||
map->figure_amount = i;
|
||||
map->size = ft_sqrt_ceil(i * 4);
|
||||
clear_map(map);
|
||||
return (map);
|
||||
}
|
17
fillit.h
Normal file
17
fillit.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
typedef struct s_tetraminos
|
||||
{
|
||||
uint16_t line[16];
|
||||
int offset_y;
|
||||
} t_tetraminos;
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
uint16_t line[16];
|
||||
unsigned int size;
|
||||
t_tetraminos *figure[26];
|
||||
unsigned int figure_amount;
|
||||
} t_map;
|
||||
|
||||
t_tetraminos *convert_tetramino(char *s);
|
||||
t_map *map_initialization(char **tetramino_table);
|
||||
|
Loading…
Reference in a new issue