From c890fe4b2f5f6b9be58ddbb6768270d6e2d71ebc Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 23:02:58 +0000 Subject: [PATCH] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 34 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 5c7aca1..cbb2f92 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -76,7 +76,6 @@ int singleplayer() { int multiplayer() { - char multi[100]; char player1[100]; char player2[100]; char ships1[100]; @@ -84,13 +83,9 @@ int multiplayer() { char letco; int numco, coor; - int score1, score2; + int score1 = 0; + int score2 = 0; - for (int i = 0; i <= 99; i++) { - - multi[i] = '0'; - - } for (int i = 0; i <= 99; i++) { @@ -156,17 +151,15 @@ int multiplayer() { printf("\n\n\n"); - !feld(player1); - - while (score1<16 !! score2 < 16) { + while (score1 || score2 < 16) { !feld(player1); - printf("Gib eine Zielkoordinate ein: "); + printf("Player 1, gib eine Zielkoordinate ein: "); scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); - if (player1[coor] == ships2[coor]) { + if (ships2[coor] = 'X') { player1[coor] = 'X'; score1 += 1; printf("Treffer!!\n"); @@ -175,7 +168,22 @@ int multiplayer() { player[coor] = '-' printf("Kein Treffer.\n") } - !feld(player1); + + !feld(player2); + printf("Player 2, gib eine Zielkoordinate ein: "); + scanf(" %c%d", &letco, &numco); + + coor = convertcoor(letco, numco); + + if (ships1[coor] == 'X') { + player2[coor] = 'X'; + score2 += 1; + printf("Treffer!!\n"); + } + else { + player2[coor] = '-'; + printf("Kein Treffer.\n"); + } }