|
|
@ -15,6 +15,7 @@ void get_next_move(double limit, Snake *snake, bool *running); |
|
|
|
void move_snake(Snake *snake); |
|
|
|
void draw(Snake *snake); |
|
|
|
int part_of_snake(Snake *snake, unsigned char tile); |
|
|
|
bool check_if_dead(Snake *snake); |
|
|
|
|
|
|
|
|
|
|
|
void snake_start(){ |
|
|
@ -59,7 +60,11 @@ void game(){ |
|
|
|
while (running){ |
|
|
|
system("clear"); |
|
|
|
draw(&snake); |
|
|
|
|
|
|
|
|
|
|
|
if(check_if_dead(&snake)){ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
t = clock() - t; |
|
|
|
get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); |
|
|
|
t = clock(); |
|
|
@ -147,4 +152,21 @@ int part_of_snake(Snake *snake, unsigned char tile){ |
|
|
|
} |
|
|
|
} |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//Wall |
|
|
|
if(snake->segments[0] % 16 == 0 || (snake->segments[0] / 16) % 16 == 0){ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |