From 4f287be714015056693dc8a2a48ede028d3f58c1 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 19:34:34 +0100 Subject: [PATCH] wall input --- src/main/c/labyrinth.c | 20 ++++++++++++++++++++ src/main/c/labyrinth.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 81b9ed4..690f831 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -26,6 +26,26 @@ void ask_lab_dimensions(unsigned short *len_x, unsigned short *len_y){ *len_y = get_natural_number("Bitte gib die y-Laenge des Labyrinthes an:\n"); } +short wall(unsigned short *x, unsigned short *y, unsigned short len_x, unsigned short len_y){ + char answer; + printf("Moechten Sie die Koordinaten einer weiteren Labyrinthwand angeben? (y/n)\n"); + scanf(" %c", &answer); + + if (answer == 'n'){ + return 1; + } + + printf("Bitte geben Sie die Koordinaten von Labyrinthwaenden im Format x, y ein.\n"); + scanf("%hu, %hu", x, y); + + if (*x >= len_x || *y >= len_y){ + printf("Die eingegebenen Koordinaten sind zu gross.\n"); + return -1; + } + + return 0; +} + void turn_direction_right(Direction *direction){ switch (*direction) { case N: diff --git a/src/main/c/labyrinth.h b/src/main/c/labyrinth.h index d9cb80c..b2160ff 100644 --- a/src/main/c/labyrinth.h +++ b/src/main/c/labyrinth.h @@ -11,5 +11,6 @@ short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Dire void show_solution(Field_State** field, unsigned short len_x, unsigned short len_y); unsigned short get_natural_number(char text[]); void ask_lab_dimensions(unsigned short *len_x, unsigned short *len_y); +short wall(unsigned short *x, unsigned short *y, unsigned short len_x, unsigned short len_y); #endif // TEST_H