so_long finished
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/26 14:29:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/01/26 16:10:23 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/01/28 18:22:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -45,3 +45,46 @@ char ft_is_empty(char **map)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_read_file_to_end(int fd)
|
||||
{
|
||||
char *gnl;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < SIZE_MAX)
|
||||
{
|
||||
gnl = get_next_line(fd);
|
||||
if (!gnl)
|
||||
return ;
|
||||
free(gnl);
|
||||
}
|
||||
free(gnl);
|
||||
}
|
||||
|
||||
char ft_checknl(char *filename)
|
||||
{
|
||||
int fd;
|
||||
size_t i;
|
||||
char *gnl;
|
||||
|
||||
i = 0;
|
||||
fd = open(filename, O_RDONLY);
|
||||
while (i < SIZE_MAX)
|
||||
{
|
||||
gnl = get_next_line(fd);
|
||||
if (!gnl)
|
||||
break ;
|
||||
if (gnl[0] == '\n')
|
||||
{
|
||||
free(gnl);
|
||||
ft_read_file_to_end(fd);
|
||||
return (1);
|
||||
}
|
||||
free(gnl);
|
||||
i++;
|
||||
}
|
||||
close (fd);
|
||||
free(gnl);
|
||||
return (0);
|
||||
}
|
||||
|
@ -6,20 +6,31 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/26 01:31:27 by adjoly #+# #+# */
|
||||
/* Updated: 2024/01/26 16:10:32 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/01/27 13:58:18 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
char ft_check_reselement(t_elemcount *count)
|
||||
{
|
||||
if (count->p_count != 1)
|
||||
{
|
||||
free(count);
|
||||
return (1);
|
||||
}
|
||||
else if (count->e_count != 1)
|
||||
{
|
||||
free(count);
|
||||
return (2);
|
||||
}
|
||||
else if (count->c_count < 1)
|
||||
{
|
||||
free(count);
|
||||
return (3);
|
||||
}
|
||||
free(count);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -57,23 +68,22 @@ void ft_check_map_content(char **map, t_coords *p_coords)
|
||||
char check_result;
|
||||
t_elemcount *count;
|
||||
|
||||
count = malloc(sizeof(t_elemcount *));
|
||||
count = malloc(sizeof(t_elemcount));
|
||||
if (!count)
|
||||
ft_send_error("Memory allocation failed\n", map);
|
||||
check_result = ft_check_element(map, p_coords, count);
|
||||
if (check_result == 1)
|
||||
{
|
||||
free(count);
|
||||
free(p_coords);
|
||||
ft_send_error("Invalid number of player\n", map);
|
||||
}
|
||||
if (check_result == 2)
|
||||
{
|
||||
free(count);
|
||||
free(p_coords);
|
||||
ft_send_error("Invalid number of exit\n", map);
|
||||
}
|
||||
if (check_result == 3)
|
||||
{
|
||||
free(count);
|
||||
free(p_coords);
|
||||
ft_send_error("Invalid number of collectible\n", map);
|
||||
}
|
||||
|
@ -6,11 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/17 10:17:52 by adjoly #+# #+# */
|
||||
/* Updated: 2024/01/26 16:10:46 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/01/28 15:18:38 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../so_long.h"
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char ft_checkcol(char **map, char c, unsigned short col)
|
||||
{
|
||||
|
Reference in New Issue
Block a user