|
@ -5,13 +5,13 @@ |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include "snake_start.h" |
|
|
#include "snake_start.h" |
|
|
#include "get_character.h" |
|
|
#include "get_character.h" |
|
|
#define TIME_TURN 0.5; |
|
|
|
|
|
|
|
|
#define TIME_TURN 0.5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main_menu(); |
|
|
void main_menu(); |
|
|
void game(); |
|
|
void game(); |
|
|
Snake initialize_snake(); |
|
|
Snake initialize_snake(); |
|
|
int *get_next_move(double limit); |
|
|
|
|
|
|
|
|
void get_next_move(double limit, Snake *snake); |
|
|
void move_snake(Snake *snake); |
|
|
void move_snake(Snake *snake); |
|
|
void draw(Snake *snake); |
|
|
void draw(Snake *snake); |
|
|
int part_of_snake(Snake *snake, unsigned char tile); |
|
|
int part_of_snake(Snake *snake, unsigned char tile); |
|
@ -56,16 +56,16 @@ void game(){ |
|
|
bool running = true; |
|
|
bool running = true; |
|
|
clock_t t = clock(); |
|
|
clock_t t = clock(); |
|
|
|
|
|
|
|
|
while (running) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
//while (running){ |
|
|
|
|
|
for(int i = 0; i < 100; i++){ |
|
|
system("clear"); |
|
|
system("clear"); |
|
|
|
|
|
draw(&snake); |
|
|
|
|
|
|
|
|
t = clock() - t; |
|
|
t = clock() - t; |
|
|
int *mv = get_next_move((double)t / CLOCKS_PER_SEC); |
|
|
|
|
|
|
|
|
get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake); |
|
|
t = clock(); |
|
|
t = clock(); |
|
|
|
|
|
|
|
|
move_snake(&snake); |
|
|
move_snake(&snake); |
|
|
draw(&snake); |
|
|
|
|
|
|
|
|
|
|
|
running = false; |
|
|
running = false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -81,13 +81,13 @@ Snake initialize_snake(){ |
|
|
snake.segments[0] = 8 + 16 * 8; |
|
|
snake.segments[0] = 8 + 16 * 8; |
|
|
snake.segments[1] = 7 + 16 * 8; |
|
|
snake.segments[1] = 7 + 16 * 8; |
|
|
snake.segments[2] = 6 + 16 * 8; |
|
|
snake.segments[2] = 6 + 16 * 8; |
|
|
|
|
|
|
|
|
|
|
|
snake.direction[0] = 1; |
|
|
|
|
|
snake.direction[1] = 0; |
|
|
return snake; |
|
|
return snake; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int *get_next_move(double limit){ |
|
|
|
|
|
limit = TIME_TURN - limit; |
|
|
|
|
|
int *ptr = (int*) malloc(2 * sizeof(int)); |
|
|
|
|
|
clock_t t = clock(); |
|
|
|
|
|
|
|
|
void get_next_move(double limit, Snake *snake){ |
|
|
char c; |
|
|
char c; |
|
|
|
|
|
|
|
|
c = get_character(limit); |
|
|
c = get_character(limit); |
|
@ -95,26 +95,28 @@ int *get_next_move(double limit){ |
|
|
switch (c){ |
|
|
switch (c){ |
|
|
case 'w': |
|
|
case 'w': |
|
|
case 'A': |
|
|
case 'A': |
|
|
printf("Hoch\n"); |
|
|
|
|
|
|
|
|
snake->direction[0] = 0; |
|
|
|
|
|
snake->direction[1] = -1; |
|
|
break; |
|
|
break; |
|
|
case 'a': |
|
|
case 'a': |
|
|
case 'D': |
|
|
case 'D': |
|
|
printf("Links\n"); |
|
|
|
|
|
|
|
|
snake->direction[0] = -1; |
|
|
|
|
|
snake->direction[1] = 0; |
|
|
break; |
|
|
break; |
|
|
case 's': |
|
|
case 's': |
|
|
case 'B': |
|
|
case 'B': |
|
|
printf("Runter\n"); |
|
|
|
|
|
|
|
|
snake->direction[0] = 0; |
|
|
|
|
|
snake->direction[1] = 1; |
|
|
break; |
|
|
break; |
|
|
case 'd': |
|
|
case 'd': |
|
|
case 'C': |
|
|
case 'C': |
|
|
printf("Rechts\n"); |
|
|
|
|
|
|
|
|
snake->direction[0] = 1; |
|
|
|
|
|
snake->direction[1] = 0; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ptr; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void move_snake(Snake *snake){ |
|
|
void move_snake(Snake *snake){ |
|
|