diff options
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/parse.c | 6 | ||||
| -rw-r--r-- | src/parse/parse_check.c | 36 | ||||
| -rw-r--r-- | src/parse/parse_color.c | 2 |
3 files changed, 31 insertions, 13 deletions
diff --git a/src/parse/parse.c b/src/parse/parse.c index 581056a..63ffb71 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 09:29:21 by cacharle #+# #+# */ -/* Updated: 2020/02/01 11:35:32 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 02:28:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,8 +32,10 @@ t_state *parse(char *filename) "parse configuration", state, lines)); } if ((state = parse_map(state, lines + i)) == NULL) + { return (error_put_return_lines_state_destroy("parse map", state, lines)); + } helper_free_splited(lines); return (state); } @@ -81,10 +83,12 @@ t_bool parse_line(t_state *state, char *line) return (TRUE); i = -1; while (++i < (int)(sizeof(g_option_parsers) / sizeof(t_option_parser))) + { if (ft_strncmp(g_option_parsers[i].id, line, ft_strlen(g_option_parsers[i].id)) == 0) return (g_option_parsers[i].func( state, line + ft_strlen(g_option_parsers[i].id) + 1)); + } return (FALSE); } diff --git a/src/parse/parse_check.c b/src/parse/parse_check.c index 5fc2674..5a36179 100644 --- a/src/parse/parse_check.c +++ b/src/parse/parse_check.c @@ -6,40 +6,54 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 10:59:15 by cacharle #+# #+# */ -/* Updated: 2020/02/02 19:42:34 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 02:26:18 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub3d.h" -t_state *parse_check(t_state *state) +static t_bool check_player_count(t_state *state) { int i; int j; int player_count; + player_count = 0; + i = -1; + while (++i < state->map_height) + { + j = -1; + while (++j < state->map_width) + if (helper_is_player_cell(state->map[i][j])) + player_count++; + } + return (player_count == 1); +} + +t_state *parse_check(t_state *state) +{ + int i; + i = -1; while (++i < state->map_width) + { if (state->map[0][i] != CELL_WALL || state->map[state->map_height - 1][i] != CELL_WALL) return (error_put_return_state_destroy( "validate map without borders", state)); + } i = -1; while (++i < state->map_height) + { if (state->map[i][0] != CELL_WALL || state->map[i][state->map_width - 1] != CELL_WALL) return (error_put_return_state_destroy( "validate map without borders", state)); - player_count = 0; - i = -1; - while (++i < state->map_height) + } + if (!check_player_count(state)) { - j = -1; - while (++j < state->map_width) - if (helper_is_player_cell(state->map[i][j])) - player_count++; + return (error_put_return_state_destroy( + "validate map with other than one player", state)); } - if (player_count != 1) - return (error_put_return_state_destroy("only one player allowed", state)); return (state); } diff --git a/src/parse/parse_color.c b/src/parse/parse_color.c index 3c025de..5385c0c 100644 --- a/src/parse/parse_color.c +++ b/src/parse/parse_color.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/11 09:52:34 by cacharle #+# #+# */ -/* Updated: 2020/02/01 11:32:33 by cacharle ### ########.fr */ +/* Updated: 2020/02/04 02:26:46 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ |
