From b021704c0545759ea2a2f2734dc5d829eca03d09 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 02:18:12 +0000 Subject: [PATCH] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 128 ++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index cb7514c..a408c89 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -74,6 +74,13 @@ int singleplayer() { char ships1[100]; char ships2[100]; + char letco; + int numco; + int coor, coor1, coor2; + int score1 = 0; + int score2 = 0; + + for (int i = 0; i <= 99; i++) { player[i] = '0'; @@ -98,6 +105,127 @@ int singleplayer() { } + !feld(ships1); + + printf("Player, platziere dein Schlachtschiff (5).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + 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); + } + + printf("Player, platziere deinen Kreuzer (4).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships1[coor1] = 'X'; + + for (int i = 0; i < 3; 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); + } + + for (int i = 0; i < 2; i++) { + printf("Player, platziere deine Zerstoerer 2x(3).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships1[coor1] = 'X'; + + for (int i = 0; i < 2; 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); + } + } + + printf("Player, platziere dein U-Boot (2).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships1[coor1] = 'X'; + + !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"); + } + + !feld(ships1); + }