Browse Source

refactoring: check_if_dead

remotes/origin/David
David Moeller 11 months ago
parent
commit
bd65725af8
  1. 9
      src/main/c/Snake/snake_start.c

9
src/main/c/Snake/snake_start.c

@ -150,7 +150,7 @@ void draw(Snake *snake, unsigned char fruit){
//returns index of segments which is identical to tile; -1 if not found
int part_of_snake(Snake *snake, unsigned char tile){
for(int i = 0; i < snake->length; i++){
for(int i = snake->length - 1; i >= 0; i--){
if(snake->segments[i] == tile){
return i;
}
@ -160,11 +160,8 @@ int part_of_snake(Snake *snake, unsigned char tile){
bool check_if_dead(Snake *snake){
//Self
for(int i = 0; i < snake->length; i++){
int part = part_of_snake(snake, snake->segments[i]);
if(part != -1 && part != i){
return true;
}
if(part_of_snake(snake, snake->segments[0]) > 0){
return true;
}
//Wall

Loading…
Cancel
Save