Browse Source

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

remotes/origin/Battleship_game
fdai7729 11 months ago
parent
commit
03b578a3d5
  1. 153
      src/main/c/Template/Battleship_game.c

153
src/main/c/Template/Battleship_game.c

@ -31,6 +31,83 @@ int feld(char prifield[]) {
printf("\n"); 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; ranvers = rand() % 5;
int randirect2 = rand() % 2; 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 //(4)-er
ranco = rand() % 4; ranco = rand() % 4;

Loading…
Cancel
Save