From 5c4520f7b03a1544b186ad9e01db4c9506c8c508 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Thu, 25 Jan 2024 11:38:19 +0100 Subject: [PATCH] adding difficulty options --- src/main/c/Snake/snake_start.c | 24 +++++++++++++++++++++--- src/main/c/main.c | 8 ++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index 68de781..f6b7996 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -5,7 +5,7 @@ #include #include "snake_start.h" #include "get_character.h" -#define TIME_TURN 0.3 +#define TURN 0.5 #define START_LENGTH 3 #define START_DIRECTION 1 #define START_TILE 8 * 16 + 8 @@ -13,6 +13,7 @@ #pragma region Funktion_heads void main_menu(); void game(); +void options(); Snake initialize_snake(); void get_next_move(double limit, Snake *snake, bool *running); void move_snake(Snake *snake); @@ -23,6 +24,10 @@ unsigned char spawn_fruit(Snake *snake); unsigned char eating_fruit(Snake *snake); #pragma endregion +#pragma region Global +double TIME_TURN = 0.5; +#pragma endregion //Global + void snake_start(){ system("clear"); main_menu(); @@ -36,7 +41,8 @@ void main_menu(){ system("clear"); printf("Waehlen Sie eine Option:\n"); printf("\t1.Start\n"); - printf("\t2.Exit\n"); + printf("\t2.Options\n"); + printf("\t3.Exit\n"); scanf("%d", &option); getchar(); @@ -48,6 +54,9 @@ void main_menu(){ game(); break; case 2: + options(); + break; + case 3: running = false; 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 snake; snake.direction = START_DIRECTION; @@ -123,7 +140,7 @@ void move_snake(Snake *snake){ } void draw(Snake *snake, unsigned char fruit){ - printf("%d\n", fruit); + printf("Score:%d Speed:%f\n", snake->length - START_LENGTH, TIME_TURN); printf("+"); for(int i = 0; i < WIDTH; i++){printf("-");} printf("+\n"); @@ -141,6 +158,7 @@ void draw(Snake *snake, unsigned char fruit){ printf("+"); for(int i = 0; i < WIDTH; i++){printf("-");} printf("+\n"); + printf("(Press q to Quit)\n"); } //returns index of segments which is identical to tile; -1 if not found diff --git a/src/main/c/main.c b/src/main/c/main.c index 27cfcae..922c8d4 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -14,9 +14,9 @@ int main(){ system("clear"); printf("Waehlen Sie eine Option:\n"); - printf("\t1.Snake starten\n"); + printf("\t1.Spiel1 starten\n"); printf("\t2.Spiel2 starten\n"); - printf("\t3.Spiel3 starten\n"); + printf("\t3.Snake starten\n"); printf("\t4.Spiel4 starten\n"); printf("\t100.Template starten\n"); printf("\t6.Exit\n"); @@ -26,13 +26,13 @@ int main(){ switch (option){ case 1: - snake_start(); + //start_game1(); break; case 2: //start_game2(); break; case 3: - //start_game3(); + snake_start(); break; case 4: //start_game4();