|
@ -5,7 +5,7 @@ |
|
|
#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.3 |
|
|
|
|
|
|
|
|
#define TURN 0.5 |
|
|
#define START_LENGTH 3 |
|
|
#define START_LENGTH 3 |
|
|
#define START_DIRECTION 1 |
|
|
#define START_DIRECTION 1 |
|
|
#define START_TILE 8 * 16 + 8 |
|
|
#define START_TILE 8 * 16 + 8 |
|
@ -13,6 +13,7 @@ |
|
|
#pragma region Funktion_heads |
|
|
#pragma region Funktion_heads |
|
|
void main_menu(); |
|
|
void main_menu(); |
|
|
void game(); |
|
|
void game(); |
|
|
|
|
|
void options(); |
|
|
Snake initialize_snake(); |
|
|
Snake initialize_snake(); |
|
|
void get_next_move(double limit, Snake *snake, bool *running); |
|
|
void get_next_move(double limit, Snake *snake, bool *running); |
|
|
void move_snake(Snake *snake); |
|
|
void move_snake(Snake *snake); |
|
@ -23,6 +24,10 @@ unsigned char spawn_fruit(Snake *snake); |
|
|
unsigned char eating_fruit(Snake *snake); |
|
|
unsigned char eating_fruit(Snake *snake); |
|
|
#pragma endregion |
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
|
|
#pragma region Global |
|
|
|
|
|
double TIME_TURN = 0.5; |
|
|
|
|
|
#pragma endregion //Global |
|
|
|
|
|
|
|
|
void snake_start(){ |
|
|
void snake_start(){ |
|
|
system("clear"); |
|
|
system("clear"); |
|
|
main_menu(); |
|
|
main_menu(); |
|
@ -36,7 +41,8 @@ void main_menu(){ |
|
|
system("clear"); |
|
|
system("clear"); |
|
|
printf("Waehlen Sie eine Option:\n"); |
|
|
printf("Waehlen Sie eine Option:\n"); |
|
|
printf("\t1.Start\n"); |
|
|
printf("\t1.Start\n"); |
|
|
printf("\t2.Exit\n"); |
|
|
|
|
|
|
|
|
printf("\t2.Options\n"); |
|
|
|
|
|
printf("\t3.Exit\n"); |
|
|
|
|
|
|
|
|
scanf("%d", &option); |
|
|
scanf("%d", &option); |
|
|
getchar(); |
|
|
getchar(); |
|
@ -48,6 +54,9 @@ void main_menu(){ |
|
|
game(); |
|
|
game(); |
|
|
break; |
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
|
|
|
options(); |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: |
|
|
running = false; |
|
|
running = false; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
@ -75,6 +84,14 @@ void game(){ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void options(){ |
|
|
|
|
|
int difficulty = 1; |
|
|
|
|
|
system("clear"); |
|
|
|
|
|
printf("Please select a difficulty(1 - 10): "); |
|
|
|
|
|
scanf("%d", &difficulty); |
|
|
|
|
|
TIME_TURN = TURN / difficulty;//(11 - difficulty) * TURN / 10; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Snake initialize_snake(){ |
|
|
Snake initialize_snake(){ |
|
|
Snake snake; |
|
|
Snake snake; |
|
|
snake.direction = START_DIRECTION; |
|
|
snake.direction = START_DIRECTION; |
|
@ -123,7 +140,7 @@ void move_snake(Snake *snake){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void draw(Snake *snake, unsigned char fruit){ |
|
|
void draw(Snake *snake, unsigned char fruit){ |
|
|
printf("%d\n", fruit); |
|
|
|
|
|
|
|
|
printf("Score:%d Speed:%f\n", snake->length - START_LENGTH, TIME_TURN); |
|
|
printf("+"); |
|
|
printf("+"); |
|
|
for(int i = 0; i < WIDTH; i++){printf("-");} |
|
|
for(int i = 0; i < WIDTH; i++){printf("-");} |
|
|
printf("+\n"); |
|
|
printf("+\n"); |
|
@ -141,6 +158,7 @@ void draw(Snake *snake, unsigned char fruit){ |
|
|
printf("+"); |
|
|
printf("+"); |
|
|
for(int i = 0; i < WIDTH; i++){printf("-");} |
|
|
for(int i = 0; i < WIDTH; i++){printf("-");} |
|
|
printf("+\n"); |
|
|
printf("+\n"); |
|
|
|
|
|
printf("(Press q to Quit)\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//returns index of segments which is identical to tile; -1 if not found |
|
|
//returns index of segments which is identical to tile; -1 if not found |
|
|