diff --git a/deel2.tar.gz b/deel2.tar.gz deleted file mode 100644 index fb6330b..0000000 Binary files a/deel2.tar.gz and /dev/null differ diff --git a/grid_game_engine.c b/grid_game_engine.c index d524226..8cd7267 100644 --- a/grid_game_engine.c +++ b/grid_game_engine.c @@ -48,7 +48,7 @@ void update_grid(rooster *rp, char c, int x, int y) { * Clears the console and prints the victory message. */ static void display_victory(void) { - clear(); + erase(); mvprintw(2,5, "YOU WON!!!!!"); refresh(); } @@ -60,7 +60,7 @@ static void display_victory(void) { * Clears the console and prints the GAME OVER message. */ static void display_loss(void) { - clear(); + erase(); mvprintw(2,5, "GAME OVER"); refresh(); } @@ -72,7 +72,7 @@ static void display_loss(void) { * Clears the console and prints the quit message. */ static void display_quit(void) { - clear(); + erase(); mvprintw(2,5, "You quit the game"); refresh(); } @@ -84,7 +84,7 @@ static void display_quit(void) { * Clears the console and prints the hacker man message. */ static void display_hackerman(void) { - clear(); + erase(); mvprintw(2,5, "The hacker man strikes again..."); refresh(); } @@ -138,6 +138,8 @@ static void init_ncurses() { init_pair(MAGENTA, COLOR_BLACK, COLOR_MAGENTA); init_pair(YELLOW, COLOR_BLACK, COLOR_YELLOW); init_pair(RED, COLOR_BLACK, COLOR_RED); + + clear(); } static void cleanup_ncurses() { diff --git a/snake.c b/snake.c index 607e91a..93ad071 100644 --- a/snake.c +++ b/snake.c @@ -5,12 +5,67 @@ #include "snake.h" #include +#include #include "grid_game_engine.h" -void snake(void) { - clear(); - mvprintw(0,0, "Snake has not yet been created"); - graceful_exit(); - refresh(); +/* + * 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) { + // erase(); + rooster* const gp = initialize_snake(); + if (gp == NULL) { + printf("Help, initializing the grid failed\n"); + } + // show_grid(gp); + // graceful_exit(); + // refresh(); } diff --git a/spel b/spel index 3f4560f..6cc0ab9 100755 Binary files a/spel and b/spel differ diff --git a/spel.c b/spel.c index 32031a0..26ee84f 100644 --- a/spel.c +++ b/spel.c @@ -13,6 +13,7 @@ #include "grid_game_engine.h" #include "minigame_menu.h" +#include "snake.h" int main(void) { init_engine();