From 37820a27b28cef00a97f02420205cda31c8ccda6 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Sun, 21 Jan 2024 13:03:36 +0100 Subject: [PATCH] Initializing Game --- src/main/c/Snake/snake_start.c | 77 ++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index 186f773..4e21045 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -1,28 +1,89 @@ #include +#include -#define HEIGHT 16 -#define WIDTH 16 +#define HEIGHT 15 +#define WIDTH 15 #define AREA HEIGHT * WIDTH - -typedef struct -{ - char direction; +typedef struct{ + signed char direction[2]; + char length; char segments[AREA]; }Snake; void main_menu(); +void game(); +Snake initialize_game(); +void draw(Snake *snake); void snake_start(){ system("clear"); - printf("Playing Snake"); - getchar(); main_menu(); } void main_menu(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Start\n"); + printf("\t2.Exit\n"); + + scanf("%d", &option); + getchar(); + + system("clear"); + + switch (option){ + case 1: + game(); + break; + case 2: + running = false; + break; + + default: + break; + } + } +} + +void game(){ + Snake snake = initialize_game(); + bool running = true; + while (running) + { + draw(&snake); + } + +} + +Snake initialize_game(){ + Snake snake = {{0, 1}, 3}; + for(int i = 0; i < AREA; i++){ + snake.segments[i] = 0; + } + snake.segments[0] = 8 + 16 * 8; + snake.segments[1] = 7 + 16 * 8; + snake.segments[2] = 6 + 16 * 8; + return snake; +} + +void draw(Snake *snake){ + printf("+"); + for(int i = 0; i < WIDTH; i++){printf("-");} + printf("+\n"); + for(int i = 0; i < HEIGHT; i++){ + for(int j = 0; j < WIDTH; j++){ + } + } + printf("+"); + for(int i = 0; i < WIDTH; i++){printf("_");} + printf("\n"); } \ No newline at end of file