Files
minigame-menu/snake.c

72 lines
1.4 KiB
C
Raw Normal View History

//
// Created by snapshot112 on 10/15/25.
//
#include "snake.h"
#include <ncurses.h>
2025-10-16 12:05:47 +02:00
#include <stdlib.h>
#include "grid_game_engine.h"
2025-10-16 12:05:47 +02:00
/*
* Create a grid for snake with a given height and width.
*
* Input:
* height: The height of the map.
* width: The width of the map.
*
* Returns:
* A pointer to the grid.
*/
static rooster *initialize_snake(void) {
int width = 10;
int height = 10;
const int grid_size = (width + 1) * height + 1;
char *map = malloc(grid_size * sizeof(char));
if (map == NULL) {
return NULL;
}
for (int i = 0; i < (width + 1) * height; i++) {
int top_line = i < width;
int bottom_line = i > grid_size - (width + 2);
int line_position = modulo(i, width + 1);
int line_start = line_position == 1;
int line_end = line_position == width;
int newline = line_position == 0;
if (newline) {
map[i] = '\n';
} else if (top_line || bottom_line || line_start || line_end) {
map[i] = '#';
}
else {
map[i] = ' ';
}
}
map[grid_size - 1] = '\0';
printf("%s", map);
rooster *grid = rooster_maak(map);
free(map);
return grid;
}
void snake(void) {
2025-10-16 12:05:47 +02:00
// erase();
rooster* const gp = initialize_snake();
if (gp == NULL) {
printf("Help, initializing the grid failed\n");
}
// show_grid(gp);
// graceful_exit();
// refresh();
}