-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnbr_of.c
More file actions
106 lines (98 loc) · 2.23 KB
/
nbr_of.c
File metadata and controls
106 lines (98 loc) · 2.23 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* nbr_of.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dhuss <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/17 13:04:13 by dhuss #+# #+# */
/* Updated: 2024/09/18 10:11:51 by dhuss ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
static void check_nbr_player(char **map)
{
size_t i;
size_t counter;
char *pos;
i = 0;
counter = 0;
while (map[i] != NULL)
{
pos = map[i];
while (1)
{
pos = ft_strchr(pos, 'P');
if (pos == NULL)
break ;
counter++;
pos++;
}
i++;
}
if (counter != 1)
{
ft_putstr_fd("Error\n", 1);
ft_putstr_fd("Incorrect number of Players\n", 1);
free_double_exit(map);
}
}
static void check_nbr_exit(char **map)
{
size_t i;
size_t counter;
char *pos;
i = 0;
counter = 0;
while (map[i] != NULL)
{
pos = map[i];
while (1)
{
pos = ft_strchr(pos, 'E');
if (pos == NULL)
break ;
counter++;
pos++;
}
i++;
}
if (counter != 1)
{
ft_putstr_fd("Error\n", 1);
ft_putstr_fd("Incorrect number of Exits\n", 1);
free_double_exit(map);
}
}
static void check_nbr_collectables(t_game_state *game)
{
size_t i;
char *pos;
i = 0;
game->collectables = 0;
while (game->map[i] != NULL)
{
pos = game->map[i];
while (1)
{
pos = ft_strchr(pos, 'C');
if (pos == NULL)
break ;
game->collectables++;
pos++;
}
i++;
}
if (game->collectables < 1)
{
ft_putstr_fd("Error\n", 1);
ft_putstr_fd("Less than one collectable\n", 1);
free_double_exit(game->map);
}
}
void check_nbr_of(t_game_state *game)
{
check_nbr_player(game->map);
check_nbr_exit(game->map);
check_nbr_collectables(game);
}