|
|
@ -2,10 +2,10 @@ |
|
|
|
#include <stdlib.h> |
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
#define max_hoehe 10 |
|
|
|
#define max_breite 10 |
|
|
|
#define zeichen_unbekannt 'x' |
|
|
|
#define zeichen_mine '@' |
|
|
|
#define max_height 10 |
|
|
|
#define max_width 10 |
|
|
|
#define unknown_character 'x' |
|
|
|
#define mine_character '@' |
|
|
|
|
|
|
|
|
|
|
|
GameResult initializeGame(TicTacToeGame* game) { |
|
|
@ -113,36 +113,36 @@ int berechneMinen(int hoehe, int breite) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
else { |
|
|
|
anzahl_minen = ((hoehe * breite) / 4); |
|
|
|
num_mines = ((height * width) / 4); |
|
|
|
} |
|
|
|
return anzahl_minen; |
|
|
|
return num_mines; |
|
|
|
} |
|
|
|
|
|
|
|
char** erschafe_minenfeld(int hoehe, int breite, char inerhalb) { |
|
|
|
char** minenfeld = (char**)calloc(hoehe, sizeof(char*)); |
|
|
|
for (int i = 0; i < hoehe; i++) { |
|
|
|
minenfeld[i] = (char*)calloc(breite, sizeof(char)); |
|
|
|
char** create_minefield(int height, int width, char within) { |
|
|
|
char** minefield = (char**)calloc(height, sizeof(char*)); |
|
|
|
for (int i = 0; i < height; i++) { |
|
|
|
minefield[i] = (char*)calloc(width, sizeof(char)); |
|
|
|
} |
|
|
|
for (int i = 0; i < hoehe; i++) { |
|
|
|
for (int j = 0; j < breite; j++) { |
|
|
|
minenfeld[i][j] = inerhalb; |
|
|
|
for (int i = 0; i < height; i++) { |
|
|
|
for (int j = 0; j < width; j++) { |
|
|
|
minefield[i][j] = within; |
|
|
|
} |
|
|
|
} |
|
|
|
return minenfeld; |
|
|
|
return minefield; |
|
|
|
} |
|
|
|
|
|
|
|
void verteile_minen(char** mienen, int hoehe, int breite, int anzahl_minen) { |
|
|
|
int i, rand_hoehe, rand_breite; |
|
|
|
void distribute_mines(char** mines, int height, int width, int num_mines) { |
|
|
|
int i, rand_height, rand_width; |
|
|
|
|
|
|
|
srand(time(NULL)); |
|
|
|
|
|
|
|
i = anzahl_minen; |
|
|
|
i = num_mines; |
|
|
|
|
|
|
|
while (i > 0) { |
|
|
|
rand_hoehe = (rand() % hoehe); |
|
|
|
rand_breite = (rand() % breite); |
|
|
|
if (mienen[rand_hoehe][rand_breite] == 0) { |
|
|
|
mienen[rand_hoehe][rand_breite] = 1; |
|
|
|
rand_height = (rand() % height); |
|
|
|
rand_width = (rand() % width); |
|
|
|
if (mines[rand_height][rand_width] == 0) { |
|
|
|
mines[rand_height][rand_width] = 1; |
|
|
|
i--; |
|
|
|
} |
|
|
|
} |
|
|
@ -160,22 +160,22 @@ void verteile_minen(char** mienen, int hoehe, int breite, int anzahl_minen) { |
|
|
|
|
|
|
|
|
|
|
|
int minesweeper() { |
|
|
|
int hoehe, breite; |
|
|
|
printf("Geben Sie an in welcher Hoehe das spielfeld sein soll:\n"); |
|
|
|
scanf("%d", &hoehe); |
|
|
|
printf("Geben Sie an welche Breite das spielfeld haben soll:\n"); |
|
|
|
scanf("%d", &breite); |
|
|
|
if (hoehe <= 0 || breite <= 0 || hoehe > max_hoehe || breite > max_breite) { |
|
|
|
printf("Ungueltige Spielfeldabmessungen.\n"); |
|
|
|
int height, width, row, column; |
|
|
|
printf("Enter the height of the game field:\n"); |
|
|
|
scanf("%d", &height); |
|
|
|
printf("Enter the width of the game field:\n"); |
|
|
|
scanf("%d", &width); |
|
|
|
if (height <= 0 || width <= 0 || height > max_height || width > max_width) { |
|
|
|
printf("Invalid field dimensions.\n"); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
int anzahl_minen = berechneMinen(hoehe, breite); |
|
|
|
printf("Das Spielfeld ist >%d< gross und hat eine Breite von >%d<\n", hoehe, breite); |
|
|
|
printf("Es gibt %d Minen auf dem Spielfeld.\n", anzahl_minen); |
|
|
|
//Matrix fuer das Spielfeld |
|
|
|
char** minenfield = erschafe_minenfeld(hoehe, breite, zeichen_unbekannt); |
|
|
|
char** minen = erschafe_minenfeld(hoehe, breite, 0); |
|
|
|
verteile_minen(minen, hoehe, breite, anzahl_minen); |
|
|
|
int num_mines = calculate_mines(height, width); |
|
|
|
printf("The game field is >%d< in height and >%d< in width.\n", height, width); |
|
|
|
printf("There are %d mines on the game field.\n", num_mines); |
|
|
|
// Matrix for the game field |
|
|
|
char** minefield = create_minefield(height, width, unknown_character); |
|
|
|
char** mines = create_minefield(height, width, 0); |
|
|
|
distribute_mines(mines, height, width, num_mines); |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|