1
0

sixty_percent

This commit is contained in:
Maelys
2024-09-16 15:09:07 +02:00
parent fa4c3d6d39
commit a6929e15e1
15 changed files with 270 additions and 55 deletions

View File

@ -20,6 +20,8 @@ SRCS = src/utils/mess_error.c \
src/utils/parse_utils.c \ src/utils/parse_utils.c \
src/parsing/check_map.c \ src/parsing/check_map.c \
src/parsing/check_arg.c \ src/parsing/check_arg.c \
src/parsing/check_id_text.c \
src/parsing/check_rgb.c \
src/parsing/principal_pars.c \ src/parsing/principal_pars.c \
src/cub3d.c src/cub3d.c

0
ea_texture.png Normal file
View File

View File

@ -6,14 +6,15 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */ /* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */
/* Updated: 2024/09/12 12:54:48 by madumerg ### ########.fr */ /* Updated: 2024/09/15 20:43:25 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef CUB3D_H #ifndef CUB3D_H
# define CUB3D_H # define CUB3D_H
# include "../libft/includes/libft.h" # include "libft.h"
# include "ft_printf.h"
# include "mess_err.h" # include "mess_err.h"
# include <stdlib.h> # include <stdlib.h>
# include <math.h> # include <math.h>

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */ /* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */
/* Updated: 2024/09/11 14:18:39 by madumerg ### ########.fr */ /* Updated: 2024/09/16 12:18:42 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,3 +23,8 @@
#define WRONG_CHAR "Invalid character in the map" #define WRONG_CHAR "Invalid character in the map"
//for permission //for permission
#define ERR_IMG "Problem with image"
#define DUP_ACR "There is a duplicate acronym"
#define DUP_IMG "There is a duplicate image"
#define NOT_FOUND "Information searched is not complete"

View File

@ -6,7 +6,7 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */ /* Created: 2024/09/12 12:49:16 by madumerg #+# #+# */
/* Updated: 2024/09/12 16:58:29 by madumerg ### ########.fr */ /* Updated: 2024/09/16 14:23:15 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,32 +21,46 @@ typedef struct s_coord
typedef struct s_pars typedef struct s_pars
{ {
int f_color; int f_color;
int c_color; int c_color;
t_coord coor; t_coord coor;
char *no_png;
char *so_png;
char *we_png;
char *ea_png;
} t_pars; } t_pars;
//check_arg.c //check_arg.c
int check_err_arg(int ac, char **av); int check_err_arg(int ac, char **av);
int check_format_file(char *file); int check_format_file(char *file);
//check_id_text.c
int check_texture(char *sign, char *path, t_pars *pars);
int detect_info(char **tab, t_pars *pars);
int check_dup_img(t_pars *pars);
//check_map.c //check_map.c
int err_not_close(char after, char before, char down, char up); int err_not_close(char after, char before, char down, char up);
int actual_char(char actual); int actual_char(char actual);
int check_map_close(char **map); int check_map_close(char **map);
int count_player(char **map); int count_player(char **map);
int check_char_map(char **map); int check_char_map(char **map);
//check_rgb.c
int check_format_rgb(char **tab);
//principal_pars.c //principal_pars.c
int verif_info_map(char *av); int verif_info_file(char *av, t_pars *pars);
int verif_all_map(char **map); int verif_all_map(char **map);
char **parse_map(char *map); char **parse_map(char *map);
//mess_error.c in utils //mess_error.c in utils
int err_mess(char *str); int err_mess(char *str);
//parse_utils.c //parse_utils.c
char **info_map(char **file); char **info_map(char **file);
void convert_white_s(char *str); void convert_white_s(char *str);
int verif_char(char c); int verif_char(char c);
int count_tab(char **tab);
int space_line(char *line);
#endif #endif

17
map.cub
View File

@ -1,14 +1,9 @@
NO ./path_to_the_north_texture NO ./no_texture.png
SO ./so_texture.png
SO ./path_to_the_south_texture WE ./we_texture.png
EA ./ea_texture.png
WE ./path_to_the_west_texture F 220 , 100, 0
C 225, 30, 0
EA ./path_to_the_east_texture
F 220,100,0
C 225,30,0
11111 11111
1001S1 1001S1

0
no_texture.png Normal file
View File

0
so_texture.png Normal file
View File

View File

@ -6,25 +6,24 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ /* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
/* Updated: 2024/09/12 16:56:30 by madumerg ### ########.fr */ /* Updated: 2024/09/16 13:54:52 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
#include "libft.h"
#include "parsing.h"
t_pars init_pars(void) t_pars init_pars(void)
{ {
t_pars new; t_pars new;
new = ft_calloc(sizeof(t_pars)); new.f_color = 0;
if (!new) new.c_color = 0;
return (NULL); new.coor.x = 0;
new->f_color = 0; new.coor.y = 0;
new->c_color = 0; new.no_png = NULL;
new->coor->x = 0; new.so_png = NULL;
new->coor->y = 0 new.we_png = NULL;
new.ea_png = NULL;
return (new); return (new);
} }
@ -32,10 +31,10 @@ int main(int ac, char **av)
{ {
t_pars pars; t_pars pars;
pars = init_pars(void); pars = init_pars();
if (check_err_arg(ac, av) == 1) if (check_err_arg(ac, av) == 1)
return (1); return (1);
if (verif_info_map(av[1], &pars) == 1) if (verif_info_file(av[1], &pars) == 1)
return (1); printf("main\n");
return (0); return (0);
} }

View File

@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_id_text.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/16 09:38:32 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:38:35 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_dup_img(t_pars *pars)
{
if (!pars->no_png || !pars->so_png || !pars->we_png || !pars->ea_png)
return (err_mess(NOT_FOUND));
if (ft_strcmp(pars->no_png, pars->so_png) == 0 || \
ft_strcmp(pars->no_png, pars->we_png) == 0 || \
ft_strcmp(pars->no_png, pars->ea_png) == 0 || \
ft_strcmp(pars->so_png, pars->we_png) == 0 || \
ft_strcmp(pars->we_png, pars->ea_png) == 0)
return (err_mess(DUP_IMG));
return (0);
}
int assign_img_two(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("WE", sign) == 0)
{
if (pars->we_png == NULL)
pars->we_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("EA", sign) == 0)
{
if (pars->ea_png == NULL)
pars->ea_png = path;
else
return (err_mess(DUP_ACR));
}
return (0);
}
int assign_img(char *sign, char *path, t_pars *pars)
{
if (ft_strcmp("NO", sign) == 0)
{
if (pars->no_png == NULL)
pars->no_png = path;
else
return (err_mess(DUP_ACR));
}
else if (ft_strcmp("SO", sign) == 0)
{
if (pars->so_png == NULL)
pars->so_png = path;
else
return (err_mess(DUP_ACR));
}
if (assign_img_two(sign, path, pars) == 1)
return (1);
return (0);
}
int check_texture(char *sign, char *path, t_pars *pars)
{
int fd;
fd = -1;
fd = open(path, O_RDONLY, 0644);
if (fd < 0)
return (err_mess(ERR_IMG));
if (assign_img(sign, path, pars) == 1)
return (1);
return (0);
}
int detect_info(char **tab, t_pars *pars)
{
if (ft_strcmp("NO", tab[0]) == 0 && count_tab(tab) == 2)
return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("SO", tab[0]) == 0 && count_tab(tab) == 2)
return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("WE", tab[0]) == 0 && count_tab(tab) == 2)
return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("EA", tab[0]) == 0 && count_tab(tab) == 2)
return (check_texture(tab[0], tab[1], pars));
else if (ft_strcmp("F", tab[0]) == 0)
check_format_rgb(tab);
else if (ft_strcmp("C", tab[0]) == 0)
check_format_rgb(tab);
else
return (err_mess(NOT_FOUND));
return (0);
}

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_rgb.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/16 09:36:07 by madumerg #+# #+# */
/* Updated: 2024/09/16 14:59:30 by madumerg ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int check_format_rgb(char **tab)
{
int i = 0;
while (tab[i])
printf(".%s.\n", tab[i++]);
return (0);
}
int create_argb(int a, int r, int g, int b)
{
return (a << 24 | r << 16 | g << 8 | b);
}

View File

@ -1,6 +1,18 @@
// convertir tt les whites spaces en simple espace sur les 6 1ere lignes // convertir tt les whites spaces en simple espace sur les 6 1ere lignes
//check si .png
WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL WARNIIIIIINNNNNNNNNNNNNGGG TESTER LES MALLOC A NULL
//faire struct de coor //faire search player
utiliser la ft pour couleur utiliser la ft pour couleur
no so
no we
no ea
so we
so ea
we ea

View File

@ -6,28 +6,53 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */ /* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
/* Updated: 2024/09/12 16:49:20 by madumerg ### ########.fr */ /* Updated: 2024/09/16 14:58:26 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int check_info(char **l) int all_data_verif(char **tab, t_pars *pars)
{ {
if (detect_info(tab, pars) == 1)
return (1);
return (0);
} }
int verif_info_map(char *av) int check_info(char **l, t_pars *pars)
{
char **tab;
int i;
i = 0;
tab = ft_calloc(sizeof(char *), 6);
if (!tab)
return (1);
while (l[i])
{
tab = ft_split(l[i], ' ');
if (all_data_verif(tab, pars) == 1)
return (1);
i++;
}
return (0);
}
int verif_info_file(char *av, t_pars *pars)
{ {
char **map; char **map;
char **f_part; char **f_part;
(void)pars;
map = parse_map(av); map = parse_map(av);
f_part = info_map(map); f_part = info_map(map);
if (check_info(f_part) == 1) if (check_info(f_part, pars) == 1)
return (1);
if (verif_all_map(map) == 1)
return (1); return (1);
// if (check_dup_img(pars) == 1)
// return (1);
// if (verif_all_map(map) == 1)
// return (1);
return (0);
} }
int verif_all_map(char **map) int verif_all_map(char **map)

View File

@ -6,27 +6,50 @@
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */ /* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */ /* Created: 2024/09/11 14:20:54 by madumerg #+# #+# */
/* Updated: 2024/09/12 16:20:31 by madumerg ### ########.fr */ /* Updated: 2024/09/16 14:55:36 by madumerg ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "cub3d.h" #include "cub3d.h"
int space_line(char *line)
{
int i;
i = 0;
convert_white_s(line);
while (line[i])
{
if (line[i] == ' ' || (line[i] >= 9 && line[i] <= 13))
i++;
else
break ;
}
if (line[i] != '\0')
return (1);
return (0);
}
char **info_map(char **file) char **info_map(char **file)
{ {
char **f_part; char **f_part;
int i; int i;
int j; int j;
i = 0; i = 0;
j = 0; j = 0;
f_part = ft_calloc(6, sizeof(char *)); f_part = ft_calloc(6, sizeof(char *));
if (!f_part) if (!f_part)
return (NULL); return (NULL);
while (i < 6) while (i >= j)
{ {
f_part[j] = file[i]; if (j == 6)
j++; break ;
if (space_line(file[i]) == 1)
{
f_part[j] = file[i];
j++;
}
i++; i++;
} }
return (f_part); return (f_part);
@ -52,3 +75,18 @@ int verif_char(char c)
return (1); return (1);
return (0); return (0);
} }
int count_tab(char **tab)
{
int i;
int ct;
i = 0;
ct = 0;
while (tab[i])
{
i++;
ct++;
}
return (ct);
}

0
we_texture.png Normal file
View File