Browse Source

refactoring: snake_collision

remotes/origin/David
David Moeller 11 months ago
parent
commit
a8b525a146
  1. 6
      src/main/c/Minesweeper/minesweeper_start.c
  2. 8
      src/main/c/Snake/snake_start.c

6
src/main/c/Minesweeper/minesweeper_start.c

@ -3,6 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <time.h> #include <time.h>
#include "minesweeper_start.h" #include "minesweeper_start.h"
#pragma region defines #pragma region defines
#define BLOCK '#' #define BLOCK '#'
#define FLAG 'x' #define FLAG 'x'
@ -15,7 +16,6 @@
#define HARD 3 #define HARD 3
#pragma endregion #pragma endregion
#pragma region Funktion_heads #pragma region Funktion_heads
void main_menu_minesweeper(); void main_menu_minesweeper();
void game_minesweeper(); void game_minesweeper();
@ -120,7 +120,7 @@ void options_minesweeper(){
switch (option){ switch (option){
case 1: case 1:
printf("Bitte neu Schwierigkeit eingeben (1 - 3): ");
printf("Bitte neue 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;
@ -128,7 +128,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 neue 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;

8
src/main/c/Snake/snake_start.c

@ -175,14 +175,10 @@ int part_of_snake(Snake *snake, unsigned char tile){
bool check_if_dead(Snake *snake){ bool check_if_dead(Snake *snake){
//Self //Self
if(part_of_snake(snake, snake->segments[0]) > 0){
return true;
}
if(part_of_snake(snake, snake->segments[0])){return true;}
//Wall //Wall
if(snake->segments[0] % 16 == 0 || (snake->segments[0] / 16) % 16 == 0){
return true;
}
if(snake->segments[0] % 16 == 0 || (snake->segments[0] / 16) % 16 == 0){return true;}
return false; return false;
} }

Loading…
Cancel
Save