newssos
This commit is contained in:
parent
15e179b4c6
commit
c7b2ed7060
55
du4/snake.c
55
du4/snake.c
@ -125,58 +125,3 @@ int step_state(struct state* state) {
|
||||
|
||||
return END_CONTINUE;
|
||||
}
|
||||
|
||||
void display_game(struct state* game) {
|
||||
printf("SNAKE GAME\n");
|
||||
|
||||
for (int y = 0; y < 10; y++) {
|
||||
for (int x = 0; x < 20; x++) {
|
||||
int head = (game->snake->x == x && game->snake->y == y);
|
||||
int body = is_snake(game->snake->next, x, y);
|
||||
int food = 0;
|
||||
|
||||
for (int i = 0; i < FOOD_COUNT; i++) {
|
||||
if (game->foodx[i] == x && game->foody[i] == y) {
|
||||
food = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (head) printf("S");
|
||||
else if (body) printf("+");
|
||||
else if (food) printf("F");
|
||||
else printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void start_game(struct state* game) {
|
||||
game->snake = add_snake(NULL, 10, 5);
|
||||
game->snake = add_snake(game->snake, 9, 5);
|
||||
|
||||
game->sx = 1;
|
||||
game->sy = 0;
|
||||
game->width = 20;
|
||||
game->height = 10;
|
||||
|
||||
for (int i = 0; i < FOOD_COUNT; i++) {
|
||||
game->foodx[i] = 5 + i * 2;
|
||||
game->foody[i] = 3 + i;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct state game;
|
||||
start_game(&game);
|
||||
|
||||
display_game(&game);
|
||||
|
||||
int status = step_state(&game);
|
||||
|
||||
printf("Game status: %d\n", status);
|
||||
|
||||
free_snake(game.snake);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user