Browse Source

adding difficulty options

remotes/origin/David
David Moeller 11 months ago
parent
commit
5c4520f7b0
  1. 24
      src/main/c/Snake/snake_start.c
  2. 8
      src/main/c/main.c

24
src/main/c/Snake/snake_start.c

@ -5,7 +5,7 @@
#include <stdlib.h>
#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

8
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();

Loading…
Cancel
Save