From ef32769e1c3f0824ee470e01f17b490461961788 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 21:35:10 +0000 Subject: [PATCH] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 42 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 39f5a59..5c7aca1 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -1,4 +1,6 @@ #include +#include + int feld(char prifield[]) { @@ -6,11 +8,11 @@ int feld(char prifield[]) { int numcoor[10]; char letcoor[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' }; - printf("--"); + printf(" "); for (int k = 0; k <= 9; k++) { numcoor[k] = k + 1; - printf("%d", numcoor[k]); + printf(" %d ", numcoor[k]); } printf("\n"); @@ -21,7 +23,7 @@ int feld(char prifield[]) { printf("%c-", letcoor[i]); for (int j = 0; j <= 9; j++) { - printf("%c", prifield[a]); + printf("[%c]", prifield[a]); a++; } @@ -82,6 +84,7 @@ int multiplayer() { char letco; int numco, coor; + int score1, score2; for (int i = 0; i <= 99; i++) { @@ -121,7 +124,7 @@ int multiplayer() { { printf("Player 1, platziere deine Schiffe.\nKoordinate: "); - scanf("%c%d", &letco, &numco); + scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); @@ -139,17 +142,44 @@ int multiplayer() { { printf("Player 2, platziere deine Schiffe.\nKoordinate: "); - scanf("%c%d", &letco, &numco); + scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); - ships1[50] = 'X'; + ships1[coor] = 'X'; !feld(ships1); k2++; } while (k2 < 17); + printf("\n\n\n"); + + + !feld(player1); + + while (score1<16 !! score2 < 16) { + + !feld(player1); + printf("Gib eine Zielkoordinate ein: "); + scanf(" %c%d", &letco, &numco); + + coor = convertcoor(letco, numco); + + if (player1[coor] == ships2[coor]) { + player1[coor] = 'X'; + score1 += 1; + printf("Treffer!!\n"); + } + else { + player[coor] = '-' + printf("Kein Treffer.\n") + } + !feld(player1); + + + } + return 0; }