Browse Source

draw Funktion

remotes/origin/David
David Moeller 11 months ago
parent
commit
189eb95704
  1. 31
      src/main/c/Snake/snake_start.c

31
src/main/c/Snake/snake_start.c

@ -9,7 +9,7 @@
typedef struct{ typedef struct{
signed char direction[2]; signed char direction[2];
char length; char length;
char segments[AREA];
unsigned char segments[AREA];
}Snake; }Snake;
@ -58,9 +58,11 @@ void game(){
bool running = true; bool running = true;
while (running) while (running)
{ {
system("clear");
draw(&snake); draw(&snake);
running = false;
} }
getchar();
} }
Snake initialize_game(){ Snake initialize_game(){
@ -78,12 +80,27 @@ void draw(Snake *snake){
printf("+"); printf("+");
for(int i = 0; i < WIDTH; i++){printf("-");} for(int i = 0; i < WIDTH; i++){printf("-");}
printf("+\n"); printf("+\n");
for(int i = 0; i < HEIGHT; i++){
for(int j = 0; j < WIDTH; j++){
for(int i = 1; i <= HEIGHT; i++){
printf("|");
for(int j = 1; j <= WIDTH; j++){
//printf("%d:", i * 16 + j);
for(int pos = 0; pos < snake->length; pos++){
//printf(" %d", snake->segments[pos]);
if(i * 16 + j == snake->segments[pos]){
if(pos == 0){
printf("0");
}else{
printf("O");
}
break;
}else if(pos == snake->length - 1){
printf(" ");
}
}
} }
printf("|\n");
} }
printf("+"); printf("+");
for(int i = 0; i < WIDTH; i++){printf("_");}
printf("\n");
for(int i = 0; i < WIDTH; i++){printf("-");}
printf("+\n");
} }
Loading…
Cancel
Save