From c8de182e9fa0c8a2674bf2f13d2ed9f500607ebd Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 4 Feb 2020 03:40:05 +0100 Subject: Norming --- src/parse/parse_check.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/parse/parse_check.c') 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } -- cgit