-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools2.c
63 lines (55 loc) · 1.88 KB
/
tools2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeparra- <yeparra-@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 20:13:55 by yeparra- #+# #+# */
/* Updated: 2024/11/14 18:30:20 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int run_check_items(t_game *game)
{
int collects;
int exit;
int player;
player = count_player(game->map, game->map_height);
collects = count_collectibles(game->map, game->map_height);
exit = count_exits(game->map, game->map_height);
if (collects >= 1 && exit == 1 && player == 1)
return (1);
return (0);
}
int check_items(t_game *game)
{
int collects;
int exit;
collects = count_collectibles(game->map, game->map_height);
exit = count_exits(game->map, game->map_height);
if (collects == 0 && exit == 0)
return (1);
return (0);
}
int game_conditions(t_game *game)
{
find_player(game);
flood_fill(game, game->pos_x, game->pos_y);
if (!check_items(game))
{
write(1, "check error items\n", 19);
return (0);
}
return (1);
}
void flood_fill(t_game *game, int x, int y)
{
if (game->map[x][y] == '1' || game->map[x][y] == 'V')
return ;
game->map[x][y] = 'V';
flood_fill(game, x - 1, y);
flood_fill(game, x + 1, y);
flood_fill(game, x, y - 1);
flood_fill(game, x, y + 1);
}