|
@ -3,7 +3,7 @@ |
|
|
#include <stdbool.h> |
|
|
#include <stdbool.h> |
|
|
#include "minesweeper_start.h" |
|
|
#include "minesweeper_start.h" |
|
|
#pragma region defines |
|
|
#pragma region defines |
|
|
#define BLOCK 219 |
|
|
|
|
|
|
|
|
#define BLOCK '#' |
|
|
#define FLAG '?' |
|
|
#define FLAG '?' |
|
|
#define EMPTY ' ' |
|
|
#define EMPTY ' ' |
|
|
#define SMALL 10 |
|
|
#define SMALL 10 |
|
@ -20,7 +20,7 @@ void main_menu_minesweeper(); |
|
|
void game_minesweeper(); |
|
|
void game_minesweeper(); |
|
|
void options_minesweeper(); |
|
|
void options_minesweeper(); |
|
|
Minesweeper_Board initialize_minesweeper(); |
|
|
Minesweeper_Board initialize_minesweeper(); |
|
|
void draw_minesweeper(); |
|
|
|
|
|
|
|
|
void draw_minesweeper(Minesweeper_Board board); |
|
|
#pragma endregion |
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
#pragma region Global |
|
|
#pragma region Global |
|
@ -69,8 +69,15 @@ void main_menu_minesweeper(){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void game_minesweeper(){ |
|
|
void game_minesweeper(){ |
|
|
Minesweeper_Board board = initialize_minesweeper(); |
|
|
|
|
|
draw_minesweeper(); |
|
|
|
|
|
|
|
|
bool running = true; |
|
|
|
|
|
int q = 0; |
|
|
|
|
|
while (running){ |
|
|
|
|
|
Minesweeper_Board board = initialize_minesweeper(); |
|
|
|
|
|
draw_minesweeper(board); |
|
|
|
|
|
|
|
|
|
|
|
scanf("%d", &q); |
|
|
|
|
|
if (q == 1){break;} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void options_minesweeper(){ |
|
|
void options_minesweeper(){ |
|
@ -90,7 +97,7 @@ void options_minesweeper(){ |
|
|
|
|
|
|
|
|
switch (option){ |
|
|
switch (option){ |
|
|
case 1: |
|
|
case 1: |
|
|
printf("Bitte neu Schwierigkeit eingeben (1 - 3):"); |
|
|
|
|
|
|
|
|
printf("Bitte neu Schwierigkeit eingeben (1 - 3): "); |
|
|
scanf("%d", &num_bombs); |
|
|
scanf("%d", &num_bombs); |
|
|
getchar(); |
|
|
getchar(); |
|
|
num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; |
|
|
num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; |
|
@ -98,7 +105,7 @@ void options_minesweeper(){ |
|
|
break; |
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
num_bombs = num_bombs < width * height / NORMAL ? EASY : num_bombs == width * height / NORMAL ? NORMAL : HARD; |
|
|
num_bombs = num_bombs < width * height / NORMAL ? EASY : num_bombs == width * height / NORMAL ? NORMAL : HARD; |
|
|
printf("Bitte neu Groesse eingeben (1 - 3):"); |
|
|
|
|
|
|
|
|
printf("Bitte neu Groesse eingeben (1 - 3): "); |
|
|
scanf("%d", &width); |
|
|
scanf("%d", &width); |
|
|
getchar(); |
|
|
getchar(); |
|
|
width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; |
|
|
width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; |
|
@ -106,13 +113,13 @@ void options_minesweeper(){ |
|
|
num_bombs = width * height / num_bombs; |
|
|
num_bombs = width * height / num_bombs; |
|
|
break; |
|
|
break; |
|
|
case 3: |
|
|
case 3: |
|
|
printf("Bitte Breite des Spielfeld eingeben:"); |
|
|
|
|
|
|
|
|
printf("Bitte Breite des Spielfeld eingeben: "); |
|
|
scanf("%d", &width); |
|
|
scanf("%d", &width); |
|
|
getchar(); |
|
|
getchar(); |
|
|
printf("Bitte Hoehe des Spielfeld eingeben:"); |
|
|
|
|
|
|
|
|
printf("Bitte Hoehe des Spielfeld eingeben: "); |
|
|
scanf("%d", &height); |
|
|
scanf("%d", &height); |
|
|
getchar(); |
|
|
getchar(); |
|
|
printf("Bitte Anzahl der Bomben eingeben:"); |
|
|
|
|
|
|
|
|
printf("Bitte Anzahl der Bomben eingeben: "); |
|
|
scanf("%d", &num_bombs); |
|
|
scanf("%d", &num_bombs); |
|
|
getchar(); |
|
|
getchar(); |
|
|
break; |
|
|
break; |
|
@ -131,13 +138,28 @@ Minesweeper_Board initialize_minesweeper(){ |
|
|
board.width = width; |
|
|
board.width = width; |
|
|
board.height = height; |
|
|
board.height = height; |
|
|
char *tiles = (char*) malloc(width * height * sizeof(char)); |
|
|
char *tiles = (char*) malloc(width * height * sizeof(char)); |
|
|
for(int i = 0; i < width * height; i++){tiles[i] = FLAG;} |
|
|
|
|
|
|
|
|
for(int i = 0; i < width * height; i++){tiles[i] = BLOCK;} |
|
|
board.tiles = tiles; |
|
|
board.tiles = tiles; |
|
|
board.num_bombs = num_bombs; |
|
|
board.num_bombs = num_bombs; |
|
|
|
|
|
|
|
|
return board; |
|
|
return board; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void draw_minesweeper(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void draw_minesweeper(Minesweeper_Board board){ |
|
|
|
|
|
printf(" "); |
|
|
|
|
|
for(int i = 0; i < board.width; i++){printf("%d", i / 10);} |
|
|
|
|
|
printf("\n "); |
|
|
|
|
|
for(int i = 0; i < board.width; i++){printf("%d", i % 10);} |
|
|
|
|
|
printf("\n +"); |
|
|
|
|
|
for(int i = 0; i < board.width; i++){printf("-");} |
|
|
|
|
|
printf("+\n"); |
|
|
|
|
|
for(int i = 0; i < board.height; i++){ |
|
|
|
|
|
printf("%d", i / 10); |
|
|
|
|
|
printf("%d|", i % 10); |
|
|
|
|
|
for(int j = 0; j < board.width; j++){printf("%c", board.tiles[i * width + j]);} |
|
|
|
|
|
printf("|\n"); |
|
|
|
|
|
} |
|
|
|
|
|
printf(" +"); |
|
|
|
|
|
for(int i = 0; i < board.width; i++){printf("-");} |
|
|
|
|
|
printf("+\n"); |
|
|
} |
|
|
} |