From e195415af470c1544ef34aba21d7876fec0700cb Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Thu, 1 Feb 2024 23:59:02 +0000 Subject: [PATCH 01/44] Upload New File --- src/main/c/Template/Battleship_game.c | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/c/Template/Battleship_game.c diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c new file mode 100644 index 0000000..0bdf810 --- /dev/null +++ b/src/main/c/Template/Battleship_game.c @@ -0,0 +1,60 @@ +#include + +int feld(char prifield[]) { + + int a = 0; + + for (int i = 0; i <= 9; i++) { + + for (int j = 0; j <= 9; j++) { + printf("%c", prifield[a]); + a++; + } + + printf("\n"); + } + + return 0; +} + +int singleplayer() { + + + + +} + +int multiplayer() { + + char multi[100]; + + for (int i = 0; i <= 99; i++) { + + multi[i] = 'X'; + + } + + !feld(multi); + + + return 0; +} + + +int main() { + + int player; + + printf("*Battleship*\n\n Single player: press <1>\n Multiplayer: press <2>\n"); + scanf("%d", &player); + + if (player == 1) { + !singleplayer(); + } + else if (player == 2) { + !multiplayer(); + } + + return 0; +} + From 733d234169258c99d31a8daf1e091c12100dde89 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 2 Feb 2024 17:48:52 +0000 Subject: [PATCH 02/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 0bdf810..9524763 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -3,9 +3,23 @@ int feld(char prifield[]) { int a = 0; + int numcoor[10]; + char letcoor[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' }; + + printf("--"); + + for (int k = 0; k <= 9; k++) { + numcoor[k] = k + 1; + printf("%d", numcoor[k]); + } + + printf("\n"); + for (int i = 0; i <= 9; i++) { + printf("%c-", letcoor[i]); + for (int j = 0; j <= 9; j++) { printf("%c", prifield[a]); a++; From 6deabe9039b60de3c6d7c7a87a6a1a5f364af7ff Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 2 Feb 2024 17:52:14 +0000 Subject: [PATCH 03/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 9524763..e9bf2e5 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -41,6 +41,10 @@ int singleplayer() { int multiplayer() { char multi[100]; + char player1[100]; + char player2[100]; + char ships1[100]; + char ships2[100]; for (int i = 0; i <= 99; i++) { @@ -48,6 +52,30 @@ int multiplayer() { } + for (int i = 0; i <= 99; i++) { + + player1[i] = 'X'; + + } + + for (int i = 0; i <= 99; i++) { + + player2[i] = 'X'; + + } + + for (int i = 0; i <= 99; i++) { + + ships1[i] = 'X'; + + } + + for (int i = 0; i <= 99; i++) { + + ships2[i] = 'X'; + + } + !feld(multi); From abc0c766a81a2450bb3f055f40eea332c2a4785b Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Mon, 5 Feb 2024 20:56:11 +0000 Subject: [PATCH 04/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index e9bf2e5..83bea8b 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -46,38 +46,50 @@ int multiplayer() { char ships1[100]; char ships2[100]; + char letco; + int numco, coor; + for (int i = 0; i <= 99; i++) { - multi[i] = 'X'; + multi[i] = '0'; } for (int i = 0; i <= 99; i++) { - player1[i] = 'X'; + player1[i] = '0'; } for (int i = 0; i <= 99; i++) { - player2[i] = 'X'; + player2[i] = '0'; } for (int i = 0; i <= 99; i++) { - ships1[i] = 'X'; + ships1[i] = '0'; } for (int i = 0; i <= 99; i++) { - ships2[i] = 'X'; + ships2[i] = '0'; } !feld(multi); + for (int i = 0; i <= 16; i++) { + + printf("Player 1, platziere deine Schiffe."); + scanf("%c%d", &letco, &numco); + + coor = convertcoor(letco, numco); + + ships1[coor] = 'X'; + return 0; } From a6629af6805612d3ed140fc84f170b97cd7fd292 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Mon, 5 Feb 2024 22:16:07 +0000 Subject: [PATCH 05/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 83bea8b..315a2aa 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -31,6 +31,40 @@ int feld(char prifield[]) { return 0; } +int convertcoor(char a, int b) { + + int co = 0; + + switch (a) { + case 'A': co = 0; break; + case 'a': co = 0; break; + case 'B': co = 10; break; + case 'b': co = 10; break; + case 'C': co = 20; break; + case 'c': co = 20; break; + case 'D': co = 30; break; + case 'd': co = 30; break; + case 'E': co = 40; break; + case 'e': co = 40; break; + case 'F': co = 50; break; + case 'f': co = 50; break; + case 'G': co = 60; break; + case 'g': co = 60; break; + case 'H': co = 70; break; + case 'h': co = 70; break; + case 'I': co = 80; break; + case 'i': co = 80; break; + case 'J': co = 90; break; + case 'j': co = 90; break; + default: co = 0; + } + + co += b; + co -= 1; + + return co; +} + int singleplayer() { From 85bbb6ad66ad75f4fb0eb3d5700b3ef1b8787af4 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 15:08:37 +0000 Subject: [PATCH 06/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 315a2aa..31faf5f 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -115,15 +115,22 @@ int multiplayer() { !feld(multi); - for (int i = 0; i <= 16; i++) { + int k = 1; - printf("Player 1, platziere deine Schiffe."); + do + { + + printf("Player 1, platziere deine Schiffe.\nKoordinate: "); scanf("%c%d", &letco, &numco); coor = convertcoor(letco, numco); ships1[coor] = 'X'; + !feld(ships1); + + k++; + } while (k < 17); return 0; } From 0ecc47c3e73540a4a1058e495786d53956ed5757 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 15:12:14 +0000 Subject: [PATCH 07/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 31faf5f..39f5a59 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -115,7 +115,7 @@ int multiplayer() { !feld(multi); - int k = 1; + int k1 = 1; do { @@ -128,9 +128,27 @@ int multiplayer() { ships1[coor] = 'X'; !feld(ships1); - k++; + k1++; - } while (k < 17); + } while (k1 < 17); + + + int k2 = 1; + + do + { + + printf("Player 2, platziere deine Schiffe.\nKoordinate: "); + scanf("%c%d", &letco, &numco); + + coor = convertcoor(letco, numco); + + ships1[50] = 'X'; + !feld(ships1); + + k2++; + + } while (k2 < 17); return 0; } From ef32769e1c3f0824ee470e01f17b490461961788 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 21:35:10 +0000 Subject: [PATCH 08/44] 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; } From c890fe4b2f5f6b9be58ddbb6768270d6e2d71ebc Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 23:02:58 +0000 Subject: [PATCH 09/44] 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"); + } } From f9ef7e6313214bdf86a0a19bf15be84e1c4ceccb Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 23:54:46 +0000 Subject: [PATCH 10/44] 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; From ba3794673b610917f520dbbbedd0d3bcd2cb7a5d Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 6 Feb 2024 23:56:16 +0000 Subject: [PATCH 11/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 874c927..9338420 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -143,7 +143,94 @@ int multiplayer() { !feld(ships1); } + printf("Player 1, 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 1, 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 1, 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); int k2 = 1; From aae3368370c71ce2d35da381a643fdb8aee89760 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 00:04:18 +0000 Subject: [PATCH 12/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 124 ++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 9 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 9338420..e06207a 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -233,22 +233,128 @@ int multiplayer() { !feld(ships1); - int k2 = 1; + printf("\n\n\n"); - do - { + !feld(ships2); - printf("Player 2, platziere deine Schiffe.\nKoordinate: "); + printf("Player 2, platziere dein Schlachtschiff (5).\nKoordinate: "); scanf(" %c%d", &letco, &numco); - coor = convertcoor(letco, numco); + coor1 = convertcoor(letco, numco); - ships1[coor] = 'X'; - !feld(ships1); + ships2[coor1] = 'X'; + + for (int i = 0; i < 4; i++) { + !feld(ships2); + printf("\n"); + scanf(" %c%d", &letco, &numco); + + coor2 = convertcoor(letco, numco); + + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else { + printf("Ungueltige Eingabe.\n"); + i--; + } + + !feld(ships2); + } + + printf("Player 2, platziere deinen Kreuzer (4).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships2[coor1] = 'X'; + + for (int i = 0; i < 3; i++) { + !feld(ships2); + printf("\n"); + scanf(" %c%d", &letco, &numco); + + coor2 = convertcoor(letco, numco); + + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else { + printf("Ungueltige Eingabe.\n"); + i--; + } + + !feld(ships2); + } + + for (int i = 0; i < 2; i++) { + printf("Player 2, platziere deine Zerstoerer 2x(3).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships2[coor1] = 'X'; + + for (int i = 0; i < 2; i++) { + !feld(ships2); + printf("\n"); + scanf(" %c%d", &letco, &numco); + + coor2 = convertcoor(letco, numco); + + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else { + printf("Ungueltige Eingabe.\n"); + i--; + } + + !feld(ships2); + } + } + + printf("Player 2, platziere dein U-Boot (2).\nKoordinate: "); + scanf(" %c%d", &letco, &numco); + + coor1 = convertcoor(letco, numco); + + ships2[coor1] = 'X'; + + !feld(ships2); + printf("\n"); + scanf(" %c%d", &letco, &numco); - k2++; + coor2 = convertcoor(letco, numco); + + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships2[coor2] = 'X'; + coor1 = coor2; + } + else { + printf("Ungueltige Eingabe.\n"); + } - } while (k2 < 17); + !feld(ships2); printf("\n\n\n"); From efcde861fccf859dae5ee41d18d05f7ff38026c9 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 00:14:07 +0000 Subject: [PATCH 13/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index e06207a..9be5bec 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -396,6 +396,13 @@ int multiplayer() { } + if (score1 = 16) { + printf("Player 1 hat gewonnen."); + } + if (score1 = 16) { + printf("Player 1 hat gewonnen."); + } + return 0; } @@ -404,7 +411,7 @@ int main() { int player; - printf("*Battleship*\n\n Single player: press <1>\n Multiplayer: press <2>\n"); + printf("*Schiffeversenken*\n\n Single player: Drück <1>\n Multiplayer: Drück <2>\n"); scanf("%d", &player); if (player == 1) { From 3073c64b17eaf395b2604f73e3c5aa3ffb754482 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 02:16:34 +0000 Subject: [PATCH 14/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 9be5bec..cb7514c 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -69,7 +69,34 @@ int convertcoor(char a, int b) { int singleplayer() { + char player[100]; + char progplayer[100]; + char ships1[100]; + char ships2[100]; + + for (int i = 0; i <= 99; i++) { + + player[i] = '0'; + + } + + for (int i = 0; i <= 99; i++) { + + progplayer[i] = '0'; + + } + for (int i = 0; i <= 99; i++) { + + ships1[i] = '0'; + + } + + for (int i = 0; i <= 99; i++) { + + ships2[i] = '0'; + + } } @@ -411,7 +438,7 @@ int main() { int player; - printf("*Schiffeversenken*\n\n Single player: Drück <1>\n Multiplayer: Drück <2>\n"); + printf("*Schiffeversenken*\n\n Single player: Drueck <1>\n Multiplayer: Drueck <2>\n"); scanf("%d", &player); if (player == 1) { From b021704c0545759ea2a2f2734dc5d829eca03d09 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 02:18:12 +0000 Subject: [PATCH 15/44] 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); + } From b87ac2585490b78d95f2d7f86955fc3975c78689 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 02:19:36 +0000 Subject: [PATCH 16/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index a408c89..1ce9e01 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -226,7 +226,26 @@ int singleplayer() { !feld(ships1); + while (score1 || score2 < 16) { + + !feld(player); + printf("Player 1, gib eine Zielkoordinate ein: "); + scanf(" %c%d", &letco, &numco); + coor = convertcoor(letco, numco); + + if (ships2[coor] == 'X') { + player[coor] = 'X'; + score1 += 1; + printf("Treffer!!\n"); + } + else { + player[coor] = '-'; + printf("Kein Treffer.\n"); + } + } + + return 0; } int multiplayer() { From 712763aff04d5a31d25a0374311fc81a4775bbd2 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 10:24:30 +0000 Subject: [PATCH 17/44] Add new file --- test/test_battleship.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/test_battleship.c diff --git a/test/test_battleship.c b/test/test_battleship.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/test_battleship.c @@ -0,0 +1 @@ + From a5773129106f3deb857d94150bab3a0f866dd343 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 10:29:23 +0000 Subject: [PATCH 18/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 1ce9e01..a508ebb 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -581,7 +581,7 @@ int multiplayer() { } -int main() { +int battleship() { int player; From a71dbc6739f659c2b53c8985e15791b74546a15d Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 10:32:35 +0000 Subject: [PATCH 19/44] Erstellen Headerdatei --- src/main/c/Template/battleship_game.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/c/Template/battleship_game.h diff --git a/src/main/c/Template/battleship_game.h b/src/main/c/Template/battleship_game.h new file mode 100644 index 0000000..129d762 --- /dev/null +++ b/src/main/c/Template/battleship_game.h @@ -0,0 +1,6 @@ +#ifndef BATTLESHIP_GAME.H +#define BATTLESHIP_GAME.H + +int battleship(); + +#endif From c7de75c1b9afefc9a339d3ffb42259cfabe5fc87 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Wed, 7 Feb 2024 23:41:11 +0000 Subject: [PATCH 20/44] =?UTF-8?q?Rundenz=C3=A4hler,=20Designanpassungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Template/Battleship_game.c | 162 ++++++++++++++++++-------- 1 file changed, 116 insertions(+), 46 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index a508ebb..60536f9 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -1,5 +1,6 @@ #include #include +#include int feld(char prifield[]) { @@ -107,8 +108,9 @@ int singleplayer() { !feld(ships1); - printf("Player, platziere dein Schlachtschiff (5).\nKoordinate: "); + printf("\nPlayer, platziere dein Schlachtschiff (5).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -116,7 +118,7 @@ int singleplayer() { for (int i = 0; i < 4; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -124,21 +126,26 @@ int singleplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships1); } - printf("Player, platziere deinen Kreuzer (4).\nKoordinate: "); + !feld(ships1); + + printf("\nPlayer, platziere deinen Kreuzer (4).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -146,7 +153,7 @@ int singleplayer() { for (int i = 0; i < 3; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -154,22 +161,28 @@ int singleplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships1); } for (int i = 0; i < 2; i++) { - printf("Player, platziere deine Zerstoerer 2x(3).\nKoordinate: "); + + !feld(ships1); + + printf("\nPlayer, platziere deine Zerstoerer 2x(3).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -177,7 +190,7 @@ int singleplayer() { for (int i = 0; i < 2; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -185,29 +198,34 @@ int singleplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships1); } } - printf("Player, platziere dein U-Boot (2).\nKoordinate: "); + !feld(ships1); + + printf("\nPlayer, platziere dein U-Boot (2).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); ships1[coor1] = 'X'; !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -215,21 +233,27 @@ int singleplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); + i--; } - !feld(ships1); + system("cls"); + + int runde = 1; while (score1 || score2 < 16) { !feld(player); - printf("Player 1, gib eine Zielkoordinate ein: "); + printf("Runde %d\n\nScore: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1); scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); @@ -243,6 +267,8 @@ int singleplayer() { player[coor] = '-'; printf("Kein Treffer.\n"); } + + runde++; } return 0; @@ -285,18 +311,23 @@ int multiplayer() { } - !feld(multi); + system("cls"); + + !feld(ships1); - printf("Player 1, platziere dein Schlachtschiff (5).\nKoordinate: "); + printf("\nPlayer 1, platziere dein Schlachtschiff (5).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); ships1[coor1] = 'X'; + !feld(ships1); + for (int i = 0; i < 4; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -304,21 +335,26 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { - printf("Ungueltige Eingabe.\n"); - i--; + system("cls"); + printf("Ungueltige Eingabe.\n"); + i--; } - !feld(ships1); } - printf("Player 1, platziere deinen Kreuzer (4).\nKoordinate: "); + !feld(ships1); + + printf("\nPlayer 1, platziere deinen Kreuzer (4).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -326,7 +362,7 @@ int multiplayer() { for (int i = 0; i < 3; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -334,22 +370,28 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships1); } for (int i = 0; i < 2; i++) { - printf("Player 1, platziere deine Zerstoerer 2x(3).\nKoordinate: "); + + !feld(ships1); + + printf("\nPlayer 1, platziere deine Zerstoerer 2x(3).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -357,7 +399,7 @@ int multiplayer() { for (int i = 0; i < 2; i++) { !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -365,29 +407,34 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships1); } } - printf("Player 1, platziere dein U-Boot (2).\nKoordinate: "); + !feld(ships1); + + printf("\nPlayer 1, platziere dein U-Boot (2).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); ships1[coor1] = 'X'; !feld(ships1); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -395,24 +442,28 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships1[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); + i--; } !feld(ships1); - - printf("\n\n\n"); + system("cls"); !feld(ships2); - printf("Player 2, platziere dein Schlachtschiff (5).\nKoordinate: "); + printf("\nPlayer 2, platziere dein Schlachtschiff (5).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -420,7 +471,7 @@ int multiplayer() { for (int i = 0; i < 4; i++) { !feld(ships2); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -428,21 +479,26 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships2); } - printf("Player 2, platziere deinen Kreuzer (4).\nKoordinate: "); + !feld(ships2); + + printf("\nPlayer 2, platziere deinen Kreuzer (4).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -450,7 +506,7 @@ int multiplayer() { for (int i = 0; i < 3; i++) { !feld(ships2); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -458,22 +514,28 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships2); } for (int i = 0; i < 2; i++) { - printf("Player 2, platziere deine Zerstoerer 2x(3).\nKoordinate: "); + + !feld(ships2); + + printf("\nPlayer 2, platziere deine Zerstoerer 2x(3).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); @@ -481,7 +543,7 @@ int multiplayer() { for (int i = 0; i < 2; i++) { !feld(ships2); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -489,29 +551,34 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); i--; } - !feld(ships2); } } - printf("Player 2, platziere dein U-Boot (2).\nKoordinate: "); + !feld(ships2); + + printf("\nPlayer 2, platziere dein U-Boot (2).\nKoordinate: "); scanf(" %c%d", &letco, &numco); + system("cls"); coor1 = convertcoor(letco, numco); ships2[coor1] = 'X'; !feld(ships2); - printf("\n"); + printf("\nKoordinate: "); scanf(" %c%d", &letco, &numco); coor2 = convertcoor(letco, numco); @@ -519,24 +586,27 @@ int multiplayer() { if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { ships2[coor2] = 'X'; coor1 = coor2; + system("cls"); } else { + system("cls"); printf("Ungueltige Eingabe.\n"); + i--; } - !feld(ships2); - - printf("\n\n\n"); + system("cls"); + int runde = 1; while (score1 || score2 < 16) { !feld(player1); - printf("Player 1, gib eine Zielkoordinate ein: "); + printf("Runde %d\n\nScore: %d\n\nPlayer 1, gib eine Zielkoordinate ein: ", runde, score1); scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); @@ -552,7 +622,7 @@ int multiplayer() { } !feld(player2); - printf("Player 2, gib eine Zielkoordinate ein: "); + printf("Runde %d\n\nScore: %d\n\nPlayer 2, gib eine Zielkoordinate ein: ", runde, score2); scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); @@ -567,7 +637,7 @@ int multiplayer() { printf("Kein Treffer.\n"); } - + runde++; } if (score1 = 16) { From 6f5a6adc7a7c69c7336f17bf9219575f69dbc951 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Thu, 8 Feb 2024 00:45:14 +0000 Subject: [PATCH 21/44] Scoresystem Refactoring --- src/main/c/Template/Battleship_game.c | 194 +++++++++++++++----------- 1 file changed, 116 insertions(+), 78 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 60536f9..752790a 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -224,52 +224,73 @@ int singleplayer() { ships1[coor1] = 'X'; - !feld(ships1); - printf("\nKoordinate: "); - scanf(" %c%d", &letco, &numco); + for (int i = 0; i < 1; i++) { + !feld(ships1); + printf("\nKoordinate: "); + scanf(" %c%d", &letco, &numco); - coor2 = convertcoor(letco, numco); + coor2 = convertcoor(letco, numco); - if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { - ships1[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { - ships1[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else { - system("cls"); - printf("Ungueltige Eingabe.\n"); - i--; + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships1[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships1[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else { + system("cls"); + printf("Ungueltige Eingabe.\n"); + i--; + } } system("cls"); int runde = 1; + int higherscore = 0; - while (score1 || score2 < 16) { + while (higherscore < 16) { - !feld(player); - printf("Runde %d\n\nScore: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1); - scanf(" %c%d", &letco, &numco); + !feld(player); + printf("Runde %d\n\nScore: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1); + scanf(" %c%d", &letco, &numco); - coor = convertcoor(letco, numco); + coor = convertcoor(letco, numco); - if (ships2[coor] == 'X') { - player[coor] = 'X'; - score1 += 1; - printf("Treffer!!\n"); - } - else { - player[coor] = '-'; - printf("Kein Treffer.\n"); + if (ships2[coor] == 'X') { + player[coor] = 'X'; + score1 += 1; + system("cls"); + printf("Treffer!!\n\n"); + } + else { + player[coor] = '-'; + system("cls"); + printf("Kein Treffer.\n\n"); + } + + if (score1 >= score2) { + higherscore = score1; + } + else { + higherscore = score2; + } + + runde++; } - runde++; - } + system("cls"); + + if (score1 = 16) { + printf("Player 1 hat gewonnen."); + } + if (score2 = 16) { + printf("Player 2 hat gewonnen."); + } return 0; } @@ -323,7 +344,6 @@ int multiplayer() { coor1 = convertcoor(letco, numco); ships1[coor1] = 'X'; - !feld(ships1); for (int i = 0; i < 4; i++) { !feld(ships1); @@ -433,26 +453,28 @@ int multiplayer() { ships1[coor1] = 'X'; - !feld(ships1); - printf("\nKoordinate: "); - scanf(" %c%d", &letco, &numco); + for (int i = 0; i < 1; i++) { + !feld(ships1); + printf("\nKoordinate: "); + scanf(" %c%d", &letco, &numco); - coor2 = convertcoor(letco, numco); + coor2 = convertcoor(letco, numco); - if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { - ships1[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { - ships1[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else { - system("cls"); - printf("Ungueltige Eingabe.\n"); - i--; + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships1[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships1[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else { + system("cls"); + printf("Ungueltige Eingabe.\n"); + i--; + } } !feld(ships1); @@ -577,33 +599,36 @@ int multiplayer() { ships2[coor1] = 'X'; - !feld(ships2); - printf("\nKoordinate: "); - scanf(" %c%d", &letco, &numco); + for (int i = 0; i < 1; i++) { + !feld(ships2); + printf("\nKoordinate: "); + scanf(" %c%d", &letco, &numco); - coor2 = convertcoor(letco, numco); + coor2 = convertcoor(letco, numco); - if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { - ships2[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { - ships2[coor2] = 'X'; - coor1 = coor2; - system("cls"); - } - else { - system("cls"); - printf("Ungueltige Eingabe.\n"); - i--; + if (coor2 == coor1 + 1 || coor2 == coor1 - 1) { + ships2[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else if (coor2 == coor1 + 10 || coor2 == coor1 - 10) { + ships2[coor2] = 'X'; + coor1 = coor2; + system("cls"); + } + else { + system("cls"); + printf("Ungueltige Eingabe.\n"); + i--; + } } system("cls"); int runde = 1; + int higherscore = 0; - while (score1 || score2 < 16) { + while (higherscore < 16) { !feld(player1); printf("Runde %d\n\nScore: %d\n\nPlayer 1, gib eine Zielkoordinate ein: ", runde, score1); @@ -611,14 +636,16 @@ int multiplayer() { coor = convertcoor(letco, numco); - if (ships2[coor] = 'X') { + if (ships2[coor] == 'X') { player1[coor] = 'X'; score1 += 1; - printf("Treffer!!\n"); + system("cls"); + printf("Treffer!!\n\n"); } else { - player[coor] = '-' - printf("Kein Treffer.\n") + player1[coor] = '-'; + system("cls"); + printf("Kein Treffer.\n"); } !feld(player2); @@ -630,21 +657,32 @@ int multiplayer() { if (ships1[coor] == 'X') { player2[coor] = 'X'; score2 += 1; - printf("Treffer!!\n"); + system("cls"); + printf("Treffer!!\n\n"); } else { player2[coor] = '-'; + system("cls"); printf("Kein Treffer.\n"); } + if (score1 >= score2) { + higherscore = score1; + } + else { + higherscore = score2; + } + runde++; } + system("cls"); + if (score1 = 16) { printf("Player 1 hat gewonnen."); } - if (score1 = 16) { - printf("Player 1 hat gewonnen."); + if (score2 = 16) { + printf("Player 2 hat gewonnen."); } return 0; From 1e2e35b0bcb131c4896d66c2a0728065bc8d5963 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Thu, 8 Feb 2024 20:02:33 +0000 Subject: [PATCH 22/44] Update test/test_battleship.c --- test/test_battleship.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_battleship.c b/test/test_battleship.c index 8b13789..68a4e16 100644 --- a/test/test_battleship.c +++ b/test/test_battleship.c @@ -1 +1,25 @@ +#ifdef TEST +#include "unity.h" +#include "battleship_game.h" + + +void setUp(void){ + +} +void tearDown(void){ +} + + +void test_convertcoor(void) { + + int output; + + + output = convertcoor('b', 5); + + + TEST_ASSERT_EQUAL_INT(14, output); +} + +#endif From b33ddd54f145f3ed0a09d73b7d481b1e3cfbeea4 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:26:00 +0000 Subject: [PATCH 23/44] hitgenerator --- src/main/c/Template/Battleship_game.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 752790a..d71e93a 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -68,6 +68,15 @@ int convertcoor(char a, int b) { return co; } +int hitgenerator() { + + int hit; + + hit = rand() % 100; + + return hit; +} + int singleplayer() { char player[100]; @@ -253,7 +262,7 @@ int singleplayer() { int runde = 1; int higherscore = 0; - while (higherscore < 16) { + while (higherscore < 17) { !feld(player); printf("Runde %d\n\nScore: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1); @@ -285,10 +294,10 @@ int singleplayer() { system("cls"); - if (score1 = 16) { + if (score1 = 17) { printf("Player 1 hat gewonnen."); } - if (score2 = 16) { + if (score2 = 17) { printf("Player 2 hat gewonnen."); } @@ -628,7 +637,7 @@ int multiplayer() { int runde = 1; int higherscore = 0; - while (higherscore < 16) { + while (higherscore < 17) { !feld(player1); printf("Runde %d\n\nScore: %d\n\nPlayer 1, gib eine Zielkoordinate ein: ", runde, score1); @@ -678,10 +687,10 @@ int multiplayer() { system("cls"); - if (score1 = 16) { + if (score1 = 17) { printf("Player 1 hat gewonnen."); } - if (score2 = 16) { + if (score2 = 17) { printf("Player 2 hat gewonnen."); } From a339d512a9838def58093393cceb81f0b5268818 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:40:27 +0000 Subject: [PATCH 24/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index d71e93a..f44829d 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -265,7 +265,7 @@ int singleplayer() { while (higherscore < 17) { !feld(player); - printf("Runde %d\n\nScore: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1); + printf("Runde %d\n\nDein Score: %d\n\nGegnerischer Score: %d\n\nPlayer, gib eine Zielkoordinate ein: ", runde, score1, score2); scanf(" %c%d", &letco, &numco); coor = convertcoor(letco, numco); @@ -282,6 +282,17 @@ int singleplayer() { printf("Kein Treffer.\n\n"); } + coor = hitgenerator(); + + int f = 0; + + while (f != 1) { + + if (progplayer[coor] == '0') { + f = 1; + } + } + if (score1 >= score2) { higherscore = score1; } From 01132fd49eafd5c29f71b5b40105a7d4d643b420 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:41:03 +0000 Subject: [PATCH 25/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index f44829d..50d9322 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -293,6 +293,18 @@ int singleplayer() { } } + if (ships1[coor] == 'X') { + progplayer[coor] = 'X'; + score2 += 1; + system("cls"); + printf("Treffer!!\n\n"); + } + else { + progplayer[coor] = '-'; + system("cls"); + printf("Kein Treffer.\n\n"); + } + if (score1 >= score2) { higherscore = score1; } From 3badada5dac81e403a630df472c1195060a01bea Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:42:32 +0000 Subject: [PATCH 26/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 50d9322..f566d42 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -68,6 +68,24 @@ int convertcoor(char a, int b) { return co; } +int* coorgenerator() { + + int randomcoor[100] = {44, 45, 55, 54, 53, 43, 33, 34, 35, 36, 46, 56, 66, 65, 64, 63, 62, 52, 42, 32, 22, 23, 24, 25, 26, 27, 37, 47, 57, 67, 77, 76, 75, 74, 73, 72, 71, 61, 51, 41, 31, 21, 11, 12, 13, 14, 15, 16, 17, 18, 28, 38, 48, 58, 68, 78, 88, 87, 86, 85, 84, 83, 82, 81, 80, 70, 60, 50, 40, 30, 20, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90}; + int shipcoor[17]; + int* shipcoorptr[17]; + int co, vers, direct; + int a = 0; + + int* returnarr = (int*)malloc(17* sizeof(int)); + + if (returnarr == NULL) { + perror("Memory allocation failed"); + exit(1); + } + + return returnarr; +} + int hitgenerator() { int hit; From e44039430c40bc3266bae52dac6ff8410eb71f61 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:43:32 +0000 Subject: [PATCH 27/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index f566d42..1a4774b 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -83,6 +83,30 @@ int* coorgenerator() { exit(1); } + srand(time(NULL)); + + //(5)-er + + int ranco = rand() % 4; + + co = randomcoor[ranco]; + + int ranvers = rand()%5; + int randirect = rand()%4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10*ranvers; + } + if (randirect == 3) { + co = co - 10*ranvers; + } + return returnarr; } From 0ed97a74cee4a5c05e465e98d66de3dd55fecf0b Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:44:10 +0000 Subject: [PATCH 28/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 1a4774b..40cc468 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -31,6 +31,50 @@ int feld(char prifield[]) { printf("\n"); } + ranvers = rand() % 5; + int randirect2 = rand() % 2; + + if (randirect == 0) { + if (randirect2 == 0) { + co = co + 10 * ranvers; + a = 1; + } + if (randirect2 == 1) { + co = co - 10 * ranvers; + a = 2; + } + } + if (randirect == 1) { + if (randirect == 0) { + co = co + 10 * ranvers; + a = 3; + } + if (randirect == 0) { + co = co - 10 * ranvers; + a = 4; + } + } + if (randirect == 2) { + if (randirect == 0) { + co = co + ranvers; + a = 1; + } + if (randirect == 0) { + co = co - ranvers; + a = 3; + } + } + if (randirect == 3) { + if (randirect == 0) { + co = co + ranvers; + a = 2; + } + if (randirect == 0) { + co = co - ranvers; + a = 4; + } + } + return 0; } From bd64d0b512549c8535896b7f0e4717ae78c0fbb5 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:44:49 +0000 Subject: [PATCH 29/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 40cc468..7caf6ef 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -75,6 +75,67 @@ int feld(char prifield[]) { } } + shipcoor[0] = co; + + int shipdirect = rand() % 2; + + if (a == 1) { + if (shipdirect == 0) { + for (int i = 1; i < 5; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 1; i < 5; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 2) { + if (shipdirect == 0) { + for (int i = 1; i < 5; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 1; i < 5; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + if (a == 3) { + if (shipdirect == 0) { + for (int i = 1; i < 5; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 1; i < 5; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 4) { + if (shipdirect == 0) { + for (int i = 1; i < 5; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 1; i < 5; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + return 0; } From e24a5c5bdb43a3e32b22407c6cb5cfe90a3c8381 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:45:34 +0000 Subject: [PATCH 30/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 7caf6ef..156d7b9 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -212,6 +212,28 @@ int* coorgenerator() { co = co - 10*ranvers; } + //(4)-er + + ranco = rand() % 4; + + co = randomcoor[ranco]; + + ranvers = rand() % 5; + randirect = rand() % 4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10 * ranvers; + } + if (randirect == 3) { + co = co - 10 * ranvers; + } + return returnarr; } From 6396028f83f38aaf54249edac36ca5814abf5966 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:46:21 +0000 Subject: [PATCH 31/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 156d7b9..c5a882a 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -234,6 +234,50 @@ int* coorgenerator() { co = co - 10 * ranvers; } + ranvers = rand() % 5; + randirect2 = rand() % 2; + + if (randirect == 0) { + if (randirect2 == 0) { + co = co + 10 * ranvers; + a = 1; + } + if (randirect2 == 1) { + co = co - 10 * ranvers; + a = 2; + } + } + if (randirect == 1) { + if (randirect == 0) { + co = co + 10 * ranvers; + a = 3; + } + if (randirect == 0) { + co = co - 10 * ranvers; + a = 4; + } + } + if (randirect == 2) { + if (randirect == 0) { + co = co + ranvers; + a = 1; + } + if (randirect == 0) { + co = co - ranvers; + a = 3; + } + } + if (randirect == 3) { + if (randirect == 0) { + co = co + ranvers; + a = 2; + } + if (randirect == 0) { + co = co - ranvers; + a = 4; + } + } + return returnarr; } From d793d1bbefeb17c62e6a52924e8b27d5d0595797 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:47:29 +0000 Subject: [PATCH 32/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index c5a882a..17bc5e6 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -278,6 +278,67 @@ int* coorgenerator() { } } + shipcoor[5] = co; + + shipdirect = rand() % 2; + + if (a == 1) { + if (shipdirect == 0) { + for (int i = 6; i < 9; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 6; i < 9; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 2) { + if (shipdirect == 0) { + for (int i = 6; i < 9; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 6; i < 9; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + if (a == 3) { + if (shipdirect == 0) { + for (int i = 6; i < 9; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 6; i < 9; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 4) { + if (shipdirect == 0) { + for (int i = 6; i < 9; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 6; i < 9; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + return returnarr; } From 99551aba4d2a20ce28f83950b8f7cc93b6401bc9 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:48:02 +0000 Subject: [PATCH 33/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 17bc5e6..7248d42 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -339,6 +339,29 @@ int* coorgenerator() { } } + //(3)-er 1 + + ranco = rand() % 4; + + co = randomcoor[ranco]; + + ranvers = rand() % 5; + randirect = rand() % 4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10 * ranvers; + } + if (randirect == 3) { + co = co - 10 * ranvers; + } + + return returnarr; } From 7467c53c6b987e10f45ec4eeba5df5802ef74faa Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:48:31 +0000 Subject: [PATCH 34/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 7248d42..584546b 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -361,6 +361,50 @@ int* coorgenerator() { co = co - 10 * ranvers; } + ranvers = rand() % 5; + randirect2 = rand() % 2; + + if (randirect == 0) { + if (randirect2 == 0) { + co = co + 10 * ranvers; + a = 1; + } + if (randirect2 == 1) { + co = co - 10 * ranvers; + a = 2; + } + } + if (randirect == 1) { + if (randirect == 0) { + co = co + 10 * ranvers; + a = 3; + } + if (randirect == 0) { + co = co - 10 * ranvers; + a = 4; + } + } + if (randirect == 2) { + if (randirect == 0) { + co = co + ranvers; + a = 1; + } + if (randirect == 0) { + co = co - ranvers; + a = 3; + } + } + if (randirect == 3) { + if (randirect == 0) { + co = co + ranvers; + a = 2; + } + if (randirect == 0) { + co = co - ranvers; + a = 4; + } + } + return returnarr; } From bd263b7845bb5b9ba5304cf89f33274cc16ff907 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:49:01 +0000 Subject: [PATCH 35/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 584546b..f98b728 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -405,6 +405,67 @@ int* coorgenerator() { } } + shipcoor[9] = co; + + shipdirect = rand() % 2; + + if (a == 1) { + if (shipdirect == 0) { + for (int i = 10; i < 12; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 10; i < 12; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 2) { + if (shipdirect == 0) { + for (int i = 10; i < 12; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 10; i < 12; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + if (a == 3) { + if (shipdirect == 0) { + for (int i = 10; i < 12; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 10; i < 12; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 4) { + if (shipdirect == 0) { + for (int i = 10; i < 12; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 10; i < 12; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + return returnarr; } From 6b47c084f8aa5e51f96d82f117daa11618a1df3d Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:49:28 +0000 Subject: [PATCH 36/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index f98b728..b449e29 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -466,6 +466,28 @@ int* coorgenerator() { } } + //(3)-er 2 + + ranco = rand() % 4; + + co = randomcoor[ranco]; + + ranvers = rand() % 5; + randirect = rand() % 4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10 * ranvers; + } + if (randirect == 3) { + co = co - 10 * ranvers; + } + return returnarr; } From 0b743e3c1489a8b44c8d35b862196307f6cd87c2 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:50:01 +0000 Subject: [PATCH 37/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index b449e29..c2d1181 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -488,6 +488,50 @@ int* coorgenerator() { co = co - 10 * ranvers; } + ranvers = rand() % 5; + randirect2 = rand() % 2; + + if (randirect == 0) { + if (randirect2 == 0) { + co = co + 10 * ranvers; + a = 1; + } + if (randirect2 == 1) { + co = co - 10 * ranvers; + a = 2; + } + } + if (randirect == 1) { + if (randirect == 0) { + co = co + 10 * ranvers; + a = 3; + } + if (randirect == 0) { + co = co - 10 * ranvers; + a = 4; + } + } + if (randirect == 2) { + if (randirect == 0) { + co = co + ranvers; + a = 1; + } + if (randirect == 0) { + co = co - ranvers; + a = 3; + } + } + if (randirect == 3) { + if (randirect == 0) { + co = co + ranvers; + a = 2; + } + if (randirect == 0) { + co = co - ranvers; + a = 4; + } + } + return returnarr; } From af63d33f6799ed97bbafe6787d54d693db4b5478 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:50:29 +0000 Subject: [PATCH 38/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index c2d1181..dd8f35d 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -532,6 +532,67 @@ int* coorgenerator() { } } + shipcoor[12] = co; + + shipdirect = rand() % 2; + + if (a == 1) { + if (shipdirect == 0) { + for (int i = 13; i < 15; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 13; i < 15; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 2) { + if (shipdirect == 0) { + for (int i = 13; i < 15; i++) { + co -= 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 13; i < 15; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + if (a == 3) { + if (shipdirect == 0) { + for (int i = 13; i < 15; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 13; i < 15; i++) { + co -= 10; + shipcoor[i] = co; + } + } + } + if (a == 4) { + if (shipdirect == 0) { + for (int i = 13; i < 15; i++) { + co += 1; + shipcoor[i] = co; + } + } + if (shipdirect == 1) { + for (int i = 13; i < 15; i++) { + co += 10; + shipcoor[i] = co; + } + } + } + return returnarr; } From 116eb7ecff7af08227232b3a8ea87eeecb5c52ee Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:50:57 +0000 Subject: [PATCH 39/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index dd8f35d..1cd0128 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -593,6 +593,28 @@ int* coorgenerator() { } } + //(2)-er + + ranco = rand() % 4; + + co = randomcoor[ranco]; + + ranvers = rand() % 5; + randirect = rand() % 4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10 * ranvers; + } + if (randirect == 3) { + co = co - 10 * ranvers; + } + return returnarr; } From 471f5cf11dc6524bb4fd31b4c4a9c490f8bfa3e9 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:51:29 +0000 Subject: [PATCH 40/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 1cd0128..1a33994 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -615,6 +615,50 @@ int* coorgenerator() { co = co - 10 * ranvers; } + ranvers = rand() % 5; + randirect2 = rand() % 2; + + if (randirect == 0) { + if (randirect2 == 0) { + co = co + 10 * ranvers; + a = 1; + } + if (randirect2 == 1) { + co = co - 10 * ranvers; + a = 2; + } + } + if (randirect == 1) { + if (randirect == 0) { + co = co + 10 * ranvers; + a = 3; + } + if (randirect == 0) { + co = co - 10 * ranvers; + a = 4; + } + } + if (randirect == 2) { + if (randirect == 0) { + co = co + ranvers; + a = 1; + } + if (randirect == 0) { + co = co - ranvers; + a = 3; + } + } + if (randirect == 3) { + if (randirect == 0) { + co = co + ranvers; + a = 2; + } + if (randirect == 0) { + co = co - ranvers; + a = 4; + } + } + return returnarr; } From 5c20512317b334f3b9ab861d75998dd630394298 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:52:03 +0000 Subject: [PATCH 41/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 1a33994..1999e97 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -659,6 +659,56 @@ int* coorgenerator() { } } + shipcoor[15] = co; + + shipdirect = rand() % 2; + + if (a == 1) { + if (shipdirect == 0) { + co -= 1; + shipcoor[16] = co; + } + if (shipdirect == 1) { + co -= 10; + shipcoor[16] = co; + } + } + if (a == 2) { + if (shipdirect == 0) { + co -= 1; + shipcoor[16] = co; + } + if (shipdirect == 1) { + co += 10; + shipcoor[16] = co; + } + } + if (a == 3) { + if (shipdirect == 0) { + co += 1; + shipcoor[16] = co; + } + if (shipdirect == 1) { + co -= 10; + shipcoor[16] = co; + } + } + if (a == 4) { + if (shipdirect == 0) { + co += 1; + shipcoor[16] = co; + } + if (shipdirect == 1) { + co += 10; + shipcoor[16] = co; + } + } + + for (int i = 0; i < 17; i++) { + + returnarr[i] = shipcoor[i]; + } + return returnarr; } From fd7e417730347ebb7b797ee8e6e49398a60904fa Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 03:53:43 +0000 Subject: [PATCH 42/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 1999e97..7bb546b 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -728,9 +728,10 @@ int singleplayer() { char progplayer[100]; char ships1[100]; char ships2[100]; + int* gencoor = coorgenerator(); char letco; - int numco; + int numco, ranco; int coor, coor1, coor2; int score1 = 0; int score2 = 0; @@ -760,6 +761,11 @@ int singleplayer() { } + for (int i = 0; i <= 18; i++) { + ranco = gencoor[i]; + ships2[ranco] = 'X'; + } + !feld(ships1); printf("\nPlayer, platziere dein Schlachtschiff (5).\nKoordinate: "); From 03b578a3d5be7e047010a8fe352e68185d96badc Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 04:00:50 +0000 Subject: [PATCH 43/44] Update src/main/c/Template/Battleship_game.c --- src/main/c/Template/Battleship_game.c | 153 +++++++++++++------------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/src/main/c/Template/Battleship_game.c b/src/main/c/Template/Battleship_game.c index 7bb546b..e0b97fa 100644 --- a/src/main/c/Template/Battleship_game.c +++ b/src/main/c/Template/Battleship_game.c @@ -31,6 +31,83 @@ int feld(char prifield[]) { printf("\n"); } + + return 0; +} + +int convertcoor(char a, int b) { + + int co = 0; + + switch (a) { + case 'A': co = 0; break; + case 'a': co = 0; break; + case 'B': co = 10; break; + case 'b': co = 10; break; + case 'C': co = 20; break; + case 'c': co = 20; break; + case 'D': co = 30; break; + case 'd': co = 30; break; + case 'E': co = 40; break; + case 'e': co = 40; break; + case 'F': co = 50; break; + case 'f': co = 50; break; + case 'G': co = 60; break; + case 'g': co = 60; break; + case 'H': co = 70; break; + case 'h': co = 70; break; + case 'I': co = 80; break; + case 'i': co = 80; break; + case 'J': co = 90; break; + case 'j': co = 90; break; + default: co = 0; + } + + co += b; + co -= 1; + + return co; +} + +int* coorgenerator() { + + int randomcoor[100] = {44, 45, 55, 54, 53, 43, 33, 34, 35, 36, 46, 56, 66, 65, 64, 63, 62, 52, 42, 32, 22, 23, 24, 25, 26, 27, 37, 47, 57, 67, 77, 76, 75, 74, 73, 72, 71, 61, 51, 41, 31, 21, 11, 12, 13, 14, 15, 16, 17, 18, 28, 38, 48, 58, 68, 78, 88, 87, 86, 85, 84, 83, 82, 81, 80, 70, 60, 50, 40, 30, 20, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90}; + int shipcoor[17]; + int* shipcoorptr[17]; + int co, vers, direct; + int a = 0; + + int* returnarr = (int*)malloc(17* sizeof(int)); + + if (returnarr == NULL) { + perror("Memory allocation failed"); + exit(1); + } + + srand(time(NULL)); + + //(5)-er + + int ranco = rand() % 4; + + co = randomcoor[ranco]; + + int ranvers = rand()%5; + int randirect = rand()%4; + + if (randirect == 0) { + co = co + ranvers; + } + if (randirect == 1) { + co = co - ranvers; + } + if (randirect == 2) { + co = co + 10*ranvers; + } + if (randirect == 3) { + co = co - 10*ranvers; + } + ranvers = rand() % 5; int randirect2 = rand() % 2; @@ -136,82 +213,6 @@ int feld(char prifield[]) { } } - return 0; -} - -int convertcoor(char a, int b) { - - int co = 0; - - switch (a) { - case 'A': co = 0; break; - case 'a': co = 0; break; - case 'B': co = 10; break; - case 'b': co = 10; break; - case 'C': co = 20; break; - case 'c': co = 20; break; - case 'D': co = 30; break; - case 'd': co = 30; break; - case 'E': co = 40; break; - case 'e': co = 40; break; - case 'F': co = 50; break; - case 'f': co = 50; break; - case 'G': co = 60; break; - case 'g': co = 60; break; - case 'H': co = 70; break; - case 'h': co = 70; break; - case 'I': co = 80; break; - case 'i': co = 80; break; - case 'J': co = 90; break; - case 'j': co = 90; break; - default: co = 0; - } - - co += b; - co -= 1; - - return co; -} - -int* coorgenerator() { - - int randomcoor[100] = {44, 45, 55, 54, 53, 43, 33, 34, 35, 36, 46, 56, 66, 65, 64, 63, 62, 52, 42, 32, 22, 23, 24, 25, 26, 27, 37, 47, 57, 67, 77, 76, 75, 74, 73, 72, 71, 61, 51, 41, 31, 21, 11, 12, 13, 14, 15, 16, 17, 18, 28, 38, 48, 58, 68, 78, 88, 87, 86, 85, 84, 83, 82, 81, 80, 70, 60, 50, 40, 30, 20, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90}; - int shipcoor[17]; - int* shipcoorptr[17]; - int co, vers, direct; - int a = 0; - - int* returnarr = (int*)malloc(17* sizeof(int)); - - if (returnarr == NULL) { - perror("Memory allocation failed"); - exit(1); - } - - srand(time(NULL)); - - //(5)-er - - int ranco = rand() % 4; - - co = randomcoor[ranco]; - - int ranvers = rand()%5; - int randirect = rand()%4; - - if (randirect == 0) { - co = co + ranvers; - } - if (randirect == 1) { - co = co - ranvers; - } - if (randirect == 2) { - co = co + 10*ranvers; - } - if (randirect == 3) { - co = co - 10*ranvers; - } - //(4)-er ranco = rand() % 4; From e9abad7b74a24159c050d9defbee786ed9cf3f1e Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Fri, 9 Feb 2024 04:04:44 +0000 Subject: [PATCH 44/44] Update test/test_battleship.c --- test/test_battleship.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_battleship.c b/test/test_battleship.c index 68a4e16..56d6aa3 100644 --- a/test/test_battleship.c +++ b/test/test_battleship.c @@ -21,5 +21,23 @@ void test_convertcoor(void) { TEST_ASSERT_EQUAL_INT(14, output); } +void setUp(void){ + +} +void tearDown(void){ +} + + +void test_convertcoor(void) { + + int output; + + + output = convertcoor('F', 6); + + + TEST_ASSERT_EQUAL_INT(55, output); +} + #endif