Browse Source

Update src/main/c/Template/Battleship_game.c

remotes/origin/Battleship_game
fdai7729 11 months ago
parent
commit
ef32769e1c
  1. 42
      src/main/c/Template/Battleship_game.c

42
src/main/c/Template/Battleship_game.c

@ -1,4 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
int feld(char prifield[]) { int feld(char prifield[]) {
@ -6,11 +8,11 @@ int feld(char prifield[]) {
int numcoor[10]; int numcoor[10];
char letcoor[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' }; char letcoor[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
printf("--");
printf(" ");
for (int k = 0; k <= 9; k++) { for (int k = 0; k <= 9; k++) {
numcoor[k] = k + 1; numcoor[k] = k + 1;
printf("%d", numcoor[k]);
printf(" %d ", numcoor[k]);
} }
printf("\n"); printf("\n");
@ -21,7 +23,7 @@ int feld(char prifield[]) {
printf("%c-", letcoor[i]); printf("%c-", letcoor[i]);
for (int j = 0; j <= 9; j++) { for (int j = 0; j <= 9; j++) {
printf("%c", prifield[a]);
printf("[%c]", prifield[a]);
a++; a++;
} }
@ -82,6 +84,7 @@ int multiplayer() {
char letco; char letco;
int numco, coor; int numco, coor;
int score1, score2;
for (int i = 0; i <= 99; i++) { for (int i = 0; i <= 99; i++) {
@ -121,7 +124,7 @@ int multiplayer() {
{ {
printf("Player 1, platziere deine Schiffe.\nKoordinate: "); printf("Player 1, platziere deine Schiffe.\nKoordinate: ");
scanf("%c%d", &letco, &numco);
scanf(" %c%d", &letco, &numco);
coor = convertcoor(letco, numco); coor = convertcoor(letco, numco);
@ -139,17 +142,44 @@ int multiplayer() {
{ {
printf("Player 2, platziere deine Schiffe.\nKoordinate: "); printf("Player 2, platziere deine Schiffe.\nKoordinate: ");
scanf("%c%d", &letco, &numco);
scanf(" %c%d", &letco, &numco);
coor = convertcoor(letco, numco); coor = convertcoor(letco, numco);
ships1[50] = 'X';
ships1[coor] = 'X';
!feld(ships1); !feld(ships1);
k2++; k2++;
} while (k2 < 17); } 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; return 0;
} }

Loading…
Cancel
Save