Browse Source

Initializing Game

remotes/origin/David
David Moeller 11 months ago
parent
commit
37820a27b2
  1. 77
      src/main/c/Snake/snake_start.c

77
src/main/c/Snake/snake_start.c

@ -1,28 +1,89 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#define HEIGHT 16
#define WIDTH 16
#define HEIGHT 15
#define WIDTH 15
#define AREA HEIGHT * WIDTH #define AREA HEIGHT * WIDTH
typedef struct
{
char direction;
typedef struct{
signed char direction[2];
char length;
char segments[AREA]; char segments[AREA];
}Snake; }Snake;
void main_menu(); void main_menu();
void game();
Snake initialize_game();
void draw(Snake *snake);
void snake_start(){ void snake_start(){
system("clear"); system("clear");
printf("Playing Snake");
getchar();
main_menu(); main_menu();
} }
void 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");
} }
Loading…
Cancel
Save