Example #1
0
int		ft_init_map(t_map *map, int size_map, char c, int nb_pieces)
{
	if (!(map->c = (char*)malloc(sizeof(char))))
		return (ERROR_MALLOC);
	*(map->c) = c;
	map->size = size_map;
	map->clear = 0;
	map->begin_line = 0;
	map->begin_column = 0;
	map->nb_pieces = nb_pieces;
	if (!(map->tab = (char **)malloc(sizeof(char *) * map->size)))
		return (ERROR_MALLOC);
	return (ft_fill_map(map));
}
Example #2
0
void	ft_init(t_tetris *tetris, int pcs)
{
	int		sqr_sze;
	char	**map;

	sqr_sze = ft_bsq(pcs);
	if ((map = ft_createmap(sqr_sze)) == NULL)
		return ;
	while (ft_fill_map(tetris, map, sqr_sze, 0) == 0)
	{
		sqr_sze++;
		free(map);
		if ((map = ft_createmap(sqr_sze)) == NULL)
			return ;
	}
	ft_display(map, sqr_sze);
}
Example #3
0
int		ft_fill_map(t_tetris *tetris, char **map, int sqr_sze, int pos)
{
	if (tetris->letter == '|')
		return (1);
	while (pos < sqr_sze * sqr_sze)
	{
		if (ft_around_tetris(tetris, map, sqr_sze, pos))
		{
			ft_put_letter(tetris, map, sqr_sze, pos);
			if (ft_fill_map(tetris + 1, map, sqr_sze, 0))
				return (1);
		}
		pos++;
	}
	ft_clean_map((tetris - 1), map, sqr_sze);
	return (0);
}
Example #4
0
void	ft_save_map(int file, t_map *map)
{
	char			*line;
	int				i;

	i = 0;
	map->spaces_count = 0;
	map->exits_count = 0;
	map->entrances_count = 0;
	map->tab = (unsigned int**)malloc(map->height * sizeof(*map->tab));
	while (i <= map->height)
	{
		map->tab[i] = (unsigned int*)malloc(map->length * sizeof(**map->tab));
		i++;
	}
	ft_fill_map(line, map, file);
	if ((map->exits_count < 1 || map->entrances_count != 1)
		&& map->error == NONE)
		map->error = WRONG_NUMBER_OF_GATES;
}