started norm
This commit is contained in:
1 parent
02875e94a6
commit
20130c1522
92 files changed
+644
-462
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -6,7 +6,7 @@
|
|||||||
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
|
# By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
# Created: 2023/11/01 11:03:22 by adjoly #+# #+# #
|
||||||
# Updated: 2024/01/19 13:41:58 by adjoly ### ########.fr #
|
# Updated: 2024/01/26 16:16:13 by adjoly ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@@ -16,9 +16,17 @@ CC = cc
|
|||||||
|
|
||||||
SRCS = main.c \
|
SRCS = main.c \
|
||||||
get_map.c \
|
get_map.c \
|
||||||
ft_move_character.c \
|
|
||||||
print_map.c \
|
print_map.c \
|
||||||
ft_check_map_error.c
|
map_error/ft_check_file.c \
|
||||||
|
map_error/ft_check_map_content.c \
|
||||||
|
map_error/ft_check_map_error.c \
|
||||||
|
map_error/ft_check_map_state.c \
|
||||||
|
map_error/ft_check_map_utils.c \
|
||||||
|
move_character/ft_move_character.c \
|
||||||
|
move_character/ft_move_down.c \
|
||||||
|
move_character/ft_move_up.c \
|
||||||
|
move_character/ft_move_left.c \
|
||||||
|
move_character/ft_move_right.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
|||||||
@@ -1,280 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_check_map_error.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/01/17 10:17:52 by adjoly #+# #+# */
|
|
||||||
/* Updated: 2024/01/24 12:35:46 by adjoly ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft/libft.h"
|
|
||||||
#include "printf/ft_printf.h"
|
|
||||||
#include "so_long.h"
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
char ft_check_charset(char c, char *charset)
|
|
||||||
{
|
|
||||||
unsigned short i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (charset[i] && i < USHRT_MAX)
|
|
||||||
{
|
|
||||||
if (c == charset[i])
|
|
||||||
return (0);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_check_file(char *file_name)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = open(file_name, O_RDONLY);
|
|
||||||
if (fd < 1)
|
|
||||||
{
|
|
||||||
close(fd);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_valid_char(char **map)
|
|
||||||
{
|
|
||||||
size_t y;
|
|
||||||
size_t x;
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
while (map[y])
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
while (map[y][x])
|
|
||||||
{
|
|
||||||
if (ft_check_charset(map[y][x], "01CEP") == 1)
|
|
||||||
return (1);
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_check_element(char **map, t_coords *p_coords)
|
|
||||||
{
|
|
||||||
size_t y;
|
|
||||||
size_t x;
|
|
||||||
size_t p_count;
|
|
||||||
size_t e_count;
|
|
||||||
size_t c_count;
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
p_count = 0;
|
|
||||||
e_count = 0;
|
|
||||||
c_count = 0;
|
|
||||||
while (map[y])
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
while (map[y][x])
|
|
||||||
{
|
|
||||||
if (map[y][x] == 'P')
|
|
||||||
{
|
|
||||||
p_count++;
|
|
||||||
p_coords->x = x;
|
|
||||||
p_coords->y = y;
|
|
||||||
}
|
|
||||||
else if (map[y][x] == 'E')
|
|
||||||
e_count++;
|
|
||||||
else if (map[y][x] == 'C')
|
|
||||||
c_count++;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
if (p_count != 1)
|
|
||||||
return (1);
|
|
||||||
else if (e_count != 1)
|
|
||||||
return (2);
|
|
||||||
else if (c_count < 1)
|
|
||||||
return (3);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_flood(int x, int y, char **map)
|
|
||||||
{
|
|
||||||
if (map[y][x] != '1')
|
|
||||||
{
|
|
||||||
map[y][x] = '1';
|
|
||||||
ft_flood(x - 1, y, map);
|
|
||||||
ft_flood(x + 1, y, map);
|
|
||||||
ft_flood(x, y - 1, map);
|
|
||||||
ft_flood(x, y + 1, map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_floodfill(char **map, t_coords *p_coords)
|
|
||||||
{
|
|
||||||
size_t x;
|
|
||||||
size_t y;
|
|
||||||
|
|
||||||
ft_flood(p_coords->x, p_coords->y, map);
|
|
||||||
y = 0;
|
|
||||||
while (map[y])
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
while (map[y][x])
|
|
||||||
{
|
|
||||||
if (map[y][x] == 'C' || map[y][x] == 'E')
|
|
||||||
return (1);
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_checkline(char *map_line, char c)
|
|
||||||
{
|
|
||||||
unsigned short i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (*map_line && i < USHRT_MAX)
|
|
||||||
{
|
|
||||||
if (*map_line != c)
|
|
||||||
return (1);
|
|
||||||
map_line++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_checkcol(char **map, char c, unsigned short col)
|
|
||||||
{
|
|
||||||
unsigned short i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (map[i] && i < USHRT_MAX)
|
|
||||||
{
|
|
||||||
if (map[i][col] != c)
|
|
||||||
return (1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_is_closed(char **map)
|
|
||||||
{
|
|
||||||
unsigned short size_map;
|
|
||||||
unsigned short size_line;
|
|
||||||
unsigned short i;
|
|
||||||
unsigned short res;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
size_map = ft_mapsize(map);
|
|
||||||
size_line = ft_strlen(map[0]);
|
|
||||||
res = ft_checkcol(map, '1', 0);
|
|
||||||
res += ft_checkcol(map, '1', size_line - 1);
|
|
||||||
res += ft_checkline(map[0], '1');
|
|
||||||
res += ft_checkline(map[size_map - 1], '1');
|
|
||||||
if (res > 0)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_is_empty(char **map)
|
|
||||||
{
|
|
||||||
if (map[0][0] == '\0')
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_is_rectangular(char **map)
|
|
||||||
{
|
|
||||||
size_t len_map;
|
|
||||||
|
|
||||||
len_map = ft_strlen(*map);
|
|
||||||
while (*map)
|
|
||||||
{
|
|
||||||
if (ft_strlen(*map) != len_map)
|
|
||||||
return (1);
|
|
||||||
map++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char ft_valid_file_ext(char *file_name)
|
|
||||||
{
|
|
||||||
unsigned short file_len;
|
|
||||||
|
|
||||||
file_len = ft_strlen(file_name) - 1;
|
|
||||||
if (file_len <= 3)
|
|
||||||
return (1);
|
|
||||||
else if (file_name[file_len] == 'r' && file_name[file_len - 1] == 'e' \
|
|
||||||
&& file_name[file_len - 2] == 'b' && file_name[file_len - 3] == '.')
|
|
||||||
return (0);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_send_error(char *msg, char **map)
|
|
||||||
{
|
|
||||||
ft_putstr_fd("Error\n", 1);
|
|
||||||
ft_putstr_fd(msg, 1);
|
|
||||||
if (map)
|
|
||||||
ft_freemap(map);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_check_map_error(char **map)
|
|
||||||
{
|
|
||||||
char check_result;
|
|
||||||
t_coords *p_coords;
|
|
||||||
|
|
||||||
p_coords = malloc(sizeof(t_coords));
|
|
||||||
if (ft_is_empty(map) == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Map is empty", map);
|
|
||||||
}
|
|
||||||
if (ft_valid_char(map) == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Invalid character in map\n", map);
|
|
||||||
}
|
|
||||||
if (ft_is_rectangular(map) == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Map is not rectengular\n", map);
|
|
||||||
}
|
|
||||||
check_result = ft_check_element(map, p_coords);
|
|
||||||
if (check_result == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Invalid number of player\n", map);
|
|
||||||
}
|
|
||||||
if (check_result == 2)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Invalid number of exit\n", map);
|
|
||||||
}
|
|
||||||
if (check_result == 3)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Invalid number of collectible\n", map);
|
|
||||||
}
|
|
||||||
if (ft_is_closed(map) == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Map is not closed\n", map);
|
|
||||||
}
|
|
||||||
if (ft_floodfill(map, p_coords) == 1)
|
|
||||||
{
|
|
||||||
free(p_coords);
|
|
||||||
ft_send_error("Map is cannot be finished\n", map);
|
|
||||||
}
|
|
||||||
free(p_coords);
|
|
||||||
}
|
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_move_character.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/01/07 19:13:01 by adjoly #+# #+# */
|
|
||||||
/* Updated: 2024/01/24 12:16:14 by adjoly ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "so_long.h"
|
|
||||||
|
|
||||||
void ft_move_up(t_window *win)
|
|
||||||
{
|
|
||||||
if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'C')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
win->map[win->p_coords->y - 1][win->p_coords->x] = '0';
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
|
||||||
win->c_count--;
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->p_coords->y == win->e_coords->y
|
|
||||||
&& win->e_coords->x == win->p_coords->x
|
|
||||||
&& win->map[win->p_coords->y - 1][win->p_coords->x] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'E'
|
|
||||||
&& win->c_count == 0)
|
|
||||||
{
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count + 1);
|
|
||||||
ft_exit(win);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y - 1][win->p_coords->x] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_down(t_window *win)
|
|
||||||
{
|
|
||||||
if (win->map[win->p_coords->y + 1][win->p_coords->x] == 'C')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
win->map[win->p_coords->y + 1][win->p_coords->x] = '0';
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
|
||||||
win->c_count--;
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->p_coords->y == win->e_coords->y
|
|
||||||
&& win->e_coords->x == win->p_coords->x
|
|
||||||
&& win->map[win->p_coords->y + 1][win->p_coords->x] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y + 1][win->p_coords->x] == 'E'
|
|
||||||
&& win->c_count == 0)
|
|
||||||
{
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count + 1);
|
|
||||||
ft_exit(win);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y + 1][win->p_coords->x] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_left(t_window *win)
|
|
||||||
{
|
|
||||||
if (win->map[win->p_coords->y][win->p_coords->x - 1] == 'C')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
win->map[win->p_coords->y][win->p_coords->x - 1] = '0';
|
|
||||||
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
|
||||||
win->c_count--;
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->p_coords->y == win->e_coords->y
|
|
||||||
&& win->e_coords->x == win->p_coords->x
|
|
||||||
&& win->map[win->p_coords->y][win->p_coords->x - 1] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
|
||||||
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y][win->p_coords->x - 1] == 'E'
|
|
||||||
&& win->c_count == 0)
|
|
||||||
{
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count + 1);
|
|
||||||
ft_exit(win);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y][win->p_coords->x - 1] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_move_right(t_window *win)
|
|
||||||
{
|
|
||||||
if (win->map[win->p_coords->y][win->p_coords->x + 1] == 'C')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
win->map[win->p_coords->y][win->p_coords->x + 1] = '0';
|
|
||||||
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
|
||||||
win->c_count--;
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->p_coords->y == win->e_coords->y
|
|
||||||
&& win->e_coords->x == win->p_coords->x
|
|
||||||
&& win->map[win->p_coords->y][win->p_coords->x + 1] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
|
||||||
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y][win->p_coords->x + 1] == 'E'
|
|
||||||
&& win->c_count == 0)
|
|
||||||
{
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count + 1);
|
|
||||||
ft_exit(win);
|
|
||||||
}
|
|
||||||
else if (win->map[win->p_coords->y][win->p_coords->x + 1] != '1')
|
|
||||||
{
|
|
||||||
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
|
||||||
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
|
||||||
win->mov_count++;
|
|
||||||
ft_printf("Mouvement : %d\n", win->mov_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_key_event(int key, void *param)
|
|
||||||
{
|
|
||||||
t_window *win;
|
|
||||||
|
|
||||||
win = (t_window *)param;
|
|
||||||
if (key == 41)
|
|
||||||
ft_exit(win);
|
|
||||||
if (key == 26 || key == 82)
|
|
||||||
ft_move_up(win);
|
|
||||||
else if (key == 22 || key == 81)
|
|
||||||
ft_move_down(win);
|
|
||||||
else if (key == 4 || key == 80)
|
|
||||||
ft_move_left(win);
|
|
||||||
else if (key == 7 || key == 79)
|
|
||||||
ft_move_right(win);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,14 @@
|
|||||||
1111111111111
|
1111111111111
|
||||||
100100000C1E1
|
1CC1CCCCCC1C1
|
||||||
100P010011101
|
1CCPC1CC111C1
|
||||||
10C0110000001
|
1CCC11CCCCCC1
|
||||||
|
1CC1CCCCCC1E1
|
||||||
|
1CCCC1CC111C1
|
||||||
|
1CC1CCCCCC1C1
|
||||||
|
1CCCC1CC111C1
|
||||||
|
1CCC11CCCCCC1
|
||||||
|
1CCC11CCCCCC1
|
||||||
|
1CC1CCCCCC111
|
||||||
|
1CCCC1CC111C1
|
||||||
|
1CCC11CCCCCC1
|
||||||
1111111111111
|
1111111111111
|
||||||
@@ -2,4 +2,7 @@
|
|||||||
100100000C1E1
|
100100000C1E1
|
||||||
100P010011101
|
100P010011101
|
||||||
10C0110000001
|
10C0110000001
|
||||||
|
100100000C1E1
|
||||||
|
100P010011101
|
||||||
|
10C0110000001
|
||||||
1111111111111
|
1111111111111
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_check_file.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
char ft_check_file(char *file_name)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open(file_name, O_RDONLY);
|
||||||
|
if (fd < 1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_valid_file_ext(char *file_name)
|
||||||
|
{
|
||||||
|
unsigned short file_len;
|
||||||
|
|
||||||
|
file_len = ft_strlen(file_name) - 1;
|
||||||
|
if (file_len <= 3)
|
||||||
|
return (1);
|
||||||
|
else if (file_name[file_len] == 'r' && file_name[file_len - 1] == 'e' \
|
||||||
|
&& file_name[file_len - 2] == 'b' && file_name[file_len - 3] == '.')
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_is_empty(char **map)
|
||||||
|
{
|
||||||
|
if (map[0][0] == '\0')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,80 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_check_map_content.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
char ft_check_reselement(t_elemcount *count)
|
||||||
|
{
|
||||||
|
if (count->p_count != 1)
|
||||||
|
return (1);
|
||||||
|
else if (count->e_count != 1)
|
||||||
|
return (2);
|
||||||
|
else if (count->c_count < 1)
|
||||||
|
return (3);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_check_element(char **map, t_coords *p_coords, t_elemcount *count)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
y = -1;
|
||||||
|
count->c_count = 0;
|
||||||
|
count->e_count = 0;
|
||||||
|
count->p_count = 0;
|
||||||
|
while (map[++y])
|
||||||
|
{
|
||||||
|
x = -1;
|
||||||
|
while (map[y][++x])
|
||||||
|
{
|
||||||
|
if (map[y][x] == 'P')
|
||||||
|
{
|
||||||
|
count->p_count++;
|
||||||
|
p_coords->x = x;
|
||||||
|
p_coords->y = y;
|
||||||
|
}
|
||||||
|
else if (map[y][x] == 'E')
|
||||||
|
count->e_count++;
|
||||||
|
else if (map[y][x] == 'C')
|
||||||
|
count->c_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ft_check_reselement(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_check_map_content(char **map, t_coords *p_coords)
|
||||||
|
{
|
||||||
|
char check_result;
|
||||||
|
t_elemcount *count;
|
||||||
|
|
||||||
|
count = malloc(sizeof(t_elemcount *));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,103 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_check_map_error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* 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 */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
char ft_checkcol(char **map, char c, unsigned short col)
|
||||||
|
{
|
||||||
|
unsigned short i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (map[i] && i < USHRT_MAX)
|
||||||
|
{
|
||||||
|
if (map[i][col] != c)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_is_rectangular(char **map)
|
||||||
|
{
|
||||||
|
size_t len_map;
|
||||||
|
|
||||||
|
len_map = ft_strlen(*map);
|
||||||
|
while (*map)
|
||||||
|
{
|
||||||
|
if (ft_strlen(*map) != len_map)
|
||||||
|
return (1);
|
||||||
|
map++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_valid_char(char **map)
|
||||||
|
{
|
||||||
|
size_t y;
|
||||||
|
size_t x;
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
while (map[y])
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
while (map[y][x])
|
||||||
|
{
|
||||||
|
if (ft_check_charset(map[y][x], "01CEP") == 1)
|
||||||
|
return (1);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_checkline(char *map_line, char c)
|
||||||
|
{
|
||||||
|
unsigned short i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (*map_line && i < USHRT_MAX)
|
||||||
|
{
|
||||||
|
if (*map_line != c)
|
||||||
|
return (1);
|
||||||
|
map_line++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_check_map_error(char **map)
|
||||||
|
{
|
||||||
|
t_coords *p_coords;
|
||||||
|
|
||||||
|
p_coords = malloc(sizeof(t_coords));
|
||||||
|
if (!p_coords)
|
||||||
|
ft_send_error("Memory allocation failed\n", map);
|
||||||
|
if (ft_is_empty(map) == 1)
|
||||||
|
{
|
||||||
|
free(p_coords);
|
||||||
|
ft_send_error("Map is empty", map);
|
||||||
|
}
|
||||||
|
if (ft_valid_char(map) == 1)
|
||||||
|
{
|
||||||
|
free(p_coords);
|
||||||
|
ft_send_error("Invalid character in map\n", map);
|
||||||
|
}
|
||||||
|
if (ft_is_rectangular(map) == 1)
|
||||||
|
{
|
||||||
|
free(p_coords);
|
||||||
|
ft_send_error("Map is not rectengular\n", map);
|
||||||
|
}
|
||||||
|
ft_check_map_content(map, p_coords);
|
||||||
|
ft_check_map_state(map, p_coords);
|
||||||
|
free(p_coords);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,79 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_check_map_state.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 14:36:23 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 16:10:55 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_flood(int x, int y, char **map)
|
||||||
|
{
|
||||||
|
if (map[y][x] != '1')
|
||||||
|
{
|
||||||
|
map[y][x] = '1';
|
||||||
|
ft_flood(x - 1, y, map);
|
||||||
|
ft_flood(x + 1, y, map);
|
||||||
|
ft_flood(x, y - 1, map);
|
||||||
|
ft_flood(x, y + 1, map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_floodfill(char **map, t_coords *p_coords)
|
||||||
|
{
|
||||||
|
size_t x;
|
||||||
|
size_t y;
|
||||||
|
|
||||||
|
ft_flood(p_coords->x, p_coords->y, map);
|
||||||
|
y = 0;
|
||||||
|
while (map[y])
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
while (map[y][x])
|
||||||
|
{
|
||||||
|
if (map[y][x] == 'C' || map[y][x] == 'E')
|
||||||
|
return (1);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_is_closed(char **map)
|
||||||
|
{
|
||||||
|
unsigned short size_map;
|
||||||
|
unsigned short size_line;
|
||||||
|
unsigned short i;
|
||||||
|
unsigned short res;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
size_map = ft_mapsize(map);
|
||||||
|
size_line = ft_strlen(map[0]);
|
||||||
|
res = ft_checkcol(map, '1', 0);
|
||||||
|
res += ft_checkcol(map, '1', size_line - 1);
|
||||||
|
res += ft_checkline(map[0], '1');
|
||||||
|
res += ft_checkline(map[size_map - 1], '1');
|
||||||
|
if (res > 0)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_check_map_state(char **map, t_coords *p_coords)
|
||||||
|
{
|
||||||
|
if (ft_is_closed(map) == 1)
|
||||||
|
{
|
||||||
|
free(p_coords);
|
||||||
|
ft_send_error("Map is not closed\n", map);
|
||||||
|
}
|
||||||
|
if (ft_floodfill(map, p_coords) == 1)
|
||||||
|
{
|
||||||
|
free(p_coords);
|
||||||
|
ft_send_error("Map is cannot be finished\n", map);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_check_map_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 15:28:38 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 16:12:43 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_send_error(char *msg, char **map)
|
||||||
|
{
|
||||||
|
ft_putstr_fd("Error\n", 1);
|
||||||
|
ft_putstr_fd(msg, 1);
|
||||||
|
if (map)
|
||||||
|
ft_freemap(map);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
char ft_check_charset(char c, char *charset)
|
||||||
|
{
|
||||||
|
unsigned short i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (charset[i] && i < USHRT_MAX)
|
||||||
|
{
|
||||||
|
if (c == charset[i])
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_move_character.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/07 19:13:01 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 16:10:05 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_printmov(t_window *win)
|
||||||
|
{
|
||||||
|
win->mov_count++;
|
||||||
|
ft_printf("Mouvement : %d\n", win->mov_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_key_event(int key, void *param)
|
||||||
|
{
|
||||||
|
t_window *win;
|
||||||
|
|
||||||
|
win = (t_window *)param;
|
||||||
|
if (key == 41)
|
||||||
|
ft_exit(win);
|
||||||
|
if (key == 26 || key == 82)
|
||||||
|
ft_move_up(win);
|
||||||
|
else if (key == 22 || key == 81)
|
||||||
|
ft_move_down(win);
|
||||||
|
else if (key == 4 || key == 80)
|
||||||
|
ft_move_left(win);
|
||||||
|
else if (key == 7 || key == 79)
|
||||||
|
ft_move_right(win);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_move_down.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 15:50:27 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 17:45:28 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_move_down(t_window *win)
|
||||||
|
{
|
||||||
|
if (win->p_coords->y == win->e_coords->y
|
||||||
|
&& win->e_coords->x == win->p_coords->x
|
||||||
|
&& win->map[win->p_coords->y + 1][win->p_coords->x] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y + 1][win->p_coords->x] == 'C')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
win->map[win->p_coords->y + 1][win->p_coords->x] = '0';
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
||||||
|
win->c_count--;
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y + 1][win->p_coords->x] == 'E'
|
||||||
|
&& win->c_count == 0)
|
||||||
|
{
|
||||||
|
ft_printmov(win);
|
||||||
|
ft_exit(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y + 1][win->p_coords->x] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y + 1, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_move_left.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 15:50:22 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 17:45:10 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_move_left(t_window *win)
|
||||||
|
{
|
||||||
|
if (win->p_coords->y == win->e_coords->y
|
||||||
|
&& win->e_coords->x == win->p_coords->x
|
||||||
|
&& win->map[win->p_coords->y][win->p_coords->x - 1] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
||||||
|
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x - 1] == 'C')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
win->map[win->p_coords->y][win->p_coords->x - 1] = '0';
|
||||||
|
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
||||||
|
win->c_count--;
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x - 1] == 'E'
|
||||||
|
&& win->c_count == 0)
|
||||||
|
{
|
||||||
|
ft_printmov(win);
|
||||||
|
ft_exit(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x - 1] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
ft_putimg(win->p_coords->x - 1, win->p_coords->y, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_move_right.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 15:50:32 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 17:44:49 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_move_right(t_window *win)
|
||||||
|
{
|
||||||
|
if (win->p_coords->y == win->e_coords->y
|
||||||
|
&& win->e_coords->x == win->p_coords->x
|
||||||
|
&& win->map[win->p_coords->y][win->p_coords->x + 1] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, 'E');
|
||||||
|
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x + 1] == 'C')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
win->map[win->p_coords->y][win->p_coords->x + 1] = '0';
|
||||||
|
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
||||||
|
win->c_count--;
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x + 1] == 'E'
|
||||||
|
&& win->c_count == 0)
|
||||||
|
{
|
||||||
|
ft_printmov(win);
|
||||||
|
ft_exit(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y][win->p_coords->x + 1] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
ft_putimg(win->p_coords->x + 1, win->p_coords->y, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_move_up.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/26 15:50:35 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/01/26 17:46:12 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../so_long.h"
|
||||||
|
|
||||||
|
void ft_move_up(t_window *win)
|
||||||
|
{
|
||||||
|
if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'C')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
win->map[win->p_coords->y - 1][win->p_coords->x] = '0';
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
||||||
|
win->c_count--;
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'C')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
win->map[win->p_coords->y - 1][win->p_coords->x] = '0';
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
||||||
|
win->c_count--;
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y - 1][win->p_coords->x] == 'E'
|
||||||
|
&& win->c_count == 0)
|
||||||
|
{
|
||||||
|
ft_printmov(win);
|
||||||
|
ft_exit(win);
|
||||||
|
}
|
||||||
|
else if (win->map[win->p_coords->y - 1][win->p_coords->x] != '1')
|
||||||
|
{
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y, win, '0');
|
||||||
|
ft_putimg(win->p_coords->x, win->p_coords->y - 1, win, 'P');
|
||||||
|
ft_printmov(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */
|
/* Created: 2024/01/06 16:19:42 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/01/24 12:15:45 by adjoly ### ########.fr */
|
/* Updated: 2024/01/26 16:15:23 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
# include "libft/libft.h"
|
# include "libft/libft.h"
|
||||||
# include "get_next_line/get_next_line.h"
|
# include "get_next_line/get_next_line.h"
|
||||||
# include "printf/ft_printf.h"
|
# include "printf/ft_printf.h"
|
||||||
|
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
@@ -44,6 +45,13 @@ typedef struct s_img
|
|||||||
void *ground;
|
void *ground;
|
||||||
} t_img;
|
} t_img;
|
||||||
|
|
||||||
|
typedef struct s_elemcount
|
||||||
|
{
|
||||||
|
size_t p_count;
|
||||||
|
size_t c_count;
|
||||||
|
size_t e_count;
|
||||||
|
} t_elemcount;
|
||||||
|
|
||||||
typedef struct s_window
|
typedef struct s_window
|
||||||
{
|
{
|
||||||
void *mlx;
|
void *mlx;
|
||||||
@@ -67,12 +75,55 @@ void ft_exit(t_window *win);
|
|||||||
|
|
||||||
void ft_printmap(char **map, t_window *win);
|
void ft_printmap(char **map, t_window *win);
|
||||||
void ft_putimg(size_t x, size_t y, t_window *win, char c);
|
void ft_putimg(size_t x, size_t y, t_window *win, char c);
|
||||||
void ft_check_map_error(char **map);
|
|
||||||
|
|
||||||
void ft_alloc_img(t_window *win);
|
void ft_alloc_img(t_window *win);
|
||||||
char ft_valid_file_ext(char *file_name);
|
|
||||||
void ft_send_error(char *msg, char **map);
|
|
||||||
void ft_check_map_error(char **map);
|
|
||||||
size_t ft_mapsize(char **map);
|
size_t ft_mapsize(char **map);
|
||||||
|
|
||||||
|
// - Move Character -
|
||||||
|
|
||||||
|
// move character
|
||||||
|
void ft_printmov(t_window *win);
|
||||||
|
int ft_key_event(int key, void *param);
|
||||||
|
|
||||||
|
// move up
|
||||||
|
void ft_move_up(t_window *win);
|
||||||
|
|
||||||
|
// move down
|
||||||
|
void ft_move_down(t_window *win);
|
||||||
|
|
||||||
|
// move left
|
||||||
|
void ft_move_left(t_window *win);
|
||||||
|
|
||||||
|
// move right
|
||||||
|
void ft_move_right(t_window *win);
|
||||||
|
|
||||||
|
// - Check Error -
|
||||||
|
|
||||||
|
// check file
|
||||||
|
char ft_check_file(char *file_name);
|
||||||
|
char ft_valid_file_ext(char *file_name);
|
||||||
|
char ft_is_empty(char **map);
|
||||||
|
|
||||||
|
//check map content
|
||||||
|
char ft_check_reselement(t_elemcount *count);
|
||||||
|
char ft_check_element(char **map, t_coords *p_coords, t_elemcount *count);
|
||||||
|
void ft_check_map_content(char **map, t_coords *p_coords);
|
||||||
|
|
||||||
|
// check map error
|
||||||
|
char ft_checkcol(char **map, char c, unsigned short col);
|
||||||
|
char ft_is_rectangular(char **map);
|
||||||
|
char ft_valid_char(char **map);
|
||||||
|
char ft_checkline(char *map_line, char c);
|
||||||
|
void ft_check_map_error(char **map);
|
||||||
|
|
||||||
|
// check map state
|
||||||
|
void ft_flood(int x, int y, char **map);
|
||||||
|
char ft_floodfill(char **map, t_coords *p_coords);
|
||||||
|
char ft_is_closed(char **map);
|
||||||
|
void ft_check_map_state(char **map, t_coords *p_coords);
|
||||||
|
|
||||||
|
// check map utils
|
||||||
|
void ft_send_error(char *msg, char **map);
|
||||||
|
char ft_check_charset(char c, char *charset);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in new issue
Block a user