|
|
@ -3,7 +3,7 @@ |
|
|
|
#include <stdbool.h> |
|
|
|
#include "minesweeper_start.h" |
|
|
|
#pragma region defines |
|
|
|
#define BLOCK 219 |
|
|
|
#define BLOCK '#' |
|
|
|
#define FLAG '?' |
|
|
|
#define EMPTY ' ' |
|
|
|
#define SMALL 10 |
|
|
@ -20,7 +20,7 @@ void main_menu_minesweeper(); |
|
|
|
void game_minesweeper(); |
|
|
|
void options_minesweeper(); |
|
|
|
Minesweeper_Board initialize_minesweeper(); |
|
|
|
void draw_minesweeper(); |
|
|
|
void draw_minesweeper(Minesweeper_Board board); |
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
#pragma region Global |
|
|
@ -69,8 +69,15 @@ void main_menu_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(){ |
|
|
@ -90,7 +97,7 @@ void options_minesweeper(){ |
|
|
|
|
|
|
|
switch (option){ |
|
|
|
case 1: |
|
|
|
printf("Bitte neu Schwierigkeit eingeben (1 - 3):"); |
|
|
|
printf("Bitte neu Schwierigkeit eingeben (1 - 3): "); |
|
|
|
scanf("%d", &num_bombs); |
|
|
|
getchar(); |
|
|
|
num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; |
|
|
@ -98,7 +105,7 @@ void options_minesweeper(){ |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
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); |
|
|
|
getchar(); |
|
|
|
width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; |
|
|
@ -106,13 +113,13 @@ void options_minesweeper(){ |
|
|
|
num_bombs = width * height / num_bombs; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
printf("Bitte Breite des Spielfeld eingeben:"); |
|
|
|
printf("Bitte Breite des Spielfeld eingeben: "); |
|
|
|
scanf("%d", &width); |
|
|
|
getchar(); |
|
|
|
printf("Bitte Hoehe des Spielfeld eingeben:"); |
|
|
|
printf("Bitte Hoehe des Spielfeld eingeben: "); |
|
|
|
scanf("%d", &height); |
|
|
|
getchar(); |
|
|
|
printf("Bitte Anzahl der Bomben eingeben:"); |
|
|
|
printf("Bitte Anzahl der Bomben eingeben: "); |
|
|
|
scanf("%d", &num_bombs); |
|
|
|
getchar(); |
|
|
|
break; |
|
|
@ -131,13 +138,28 @@ Minesweeper_Board initialize_minesweeper(){ |
|
|
|
board.width = width; |
|
|
|
board.height = height; |
|
|
|
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.num_bombs = num_bombs; |
|
|
|
|
|
|
|
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"); |
|
|
|
} |