From f9ef7e6313214bdf86a0a19bf15be84e1c4ceccb Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 23:54:46 +0000 Subject: [PATCH] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 39 ++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index cbb2f92..874c927 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -82,7 +82,7 @@ int multiplayer() { char ships2[100]; char letco; - int numco, coor; + int numco, coor, coor1, coor2; int score1 = 0; int score2 = 0; @@ -113,22 +113,37 @@ int multiplayer() { !feld(multi); - int k1 = 1; - do - { - - printf("Player 1, platziere deine Schiffe.\nKoordinate: "); + printf("Player 1, platziere dein Schlachtschiff (5).\nKoordinate: "); scanf(" %c%d", &letco, &numco); - coor = convertcoor(letco, numco); - - ships1[coor] = 'X'; - !feld(ships1); + coor1 = convertcoor(letco, numco); + + ships1[coor1] = 'X'; + for (int i = 0; i < 4; i++) { + !feld(ships1); + printf("\n"); + scanf(" %c%d", &letco, &numco); + + coor2 = convertcoor(letco, numco); + + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships1[coor2] = 'X'; + coor1 = coor2; + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships1[coor2] = 'X'; + coor1 = coor2; + } + else { + printf("Ungueltige Eingabe.\n"); + i--; + } + + !feld(ships1); + } - k1++; - } while (k1 < 17); int k2 = 1;