diff --git a/deel2.tar.gz b/deel2.tar.gz new file mode 100644 index 0000000..d883cfd Binary files /dev/null and b/deel2.tar.gz differ diff --git a/grid.c b/grid.c index 2224b50..6489548 100644 --- a/grid.c +++ b/grid.c @@ -1,3 +1,8 @@ +/* + * Created by snapshot112 on 2/10/2025 + */ + + #include "grid.h" #include @@ -8,12 +13,15 @@ * The grid type this program is build around. */ typedef struct grid_data { - char *rost; + char *locations; int height; int width; state state; } grid; +/* + * Translate x and y coordinates to a location index on the grid. + */ static int internal_location(const grid *gp, const int x, const int y) { return y * (gp->width + 1) + x; } @@ -48,12 +56,12 @@ grid *grid_create_from_string(const char* input) { return NULL; } - gp->rost = malloc(grid_size * sizeof(char)); + gp->locations = malloc(grid_size * sizeof(char)); gp->height = height; gp->width = width; gp->state = STATE_BEGIN; - strcpy(gp->rost, input); + strcpy(gp->locations, input); return gp; } @@ -62,8 +70,8 @@ grid *grid_create_from_string(const char* input) { * Sets a grids width and height * * Input: - * fh: the stream to read the grid from. - * rost: a grid file to store the width and height in. + * fh: The stream to read the grid from. + * gp: A pointer to the grid whose width and height you want to set. * * Side effects: * the grid gets its width and height set @@ -72,27 +80,27 @@ grid *grid_create_from_string(const char* input) { * 1 if the file width and height seem to match with its size * 0 otherwise */ -static int get_grid_sizes(FILE *fh, grid *rost) { +static int get_grid_sizes(FILE *fh, grid *gp) { while (getc(fh) != '\n') { if (feof(fh)) { return 0; } - rost->width++; + gp->width++; } - if (rost->width == 0) { + if (gp->width == 0) { return 0; } fseek(fh, 0, SEEK_END); // Get file size (- 1 for the blank newline and EOF at the end) - if (ftell(fh) % (rost->width + 1) != 0) { + if (ftell(fh) % (gp->width + 1) != 0) { // Not all lines are the same width return 0; } - rost->height = (int)ftell(fh) / (int)sizeof(char) / (rost->width + 1); + gp->height = (int)ftell(fh) / (int)sizeof(char) / (gp->width + 1); fseek(fh, 0, SEEK_SET); return 1; @@ -103,7 +111,7 @@ grid *grid_create_from_file(FILE *fh) { return NULL; } - grid rost = { + grid temp_grid = { NULL, 0, 0, @@ -111,52 +119,52 @@ grid *grid_create_from_file(FILE *fh) { }; // Sets the width and height of the grid. - if (get_grid_sizes(fh, &rost) != 1) { + if (get_grid_sizes(fh, &temp_grid) != 1) { // Unlogical file structure. return NULL; } - const int grid_size = (rost.width + 1) * rost.height + 1; + const int grid_size = (temp_grid.width + 1) * temp_grid.height + 1; - rost.rost = malloc(grid_size * sizeof(char)); - if (rost.rost == NULL) { + temp_grid.locations = malloc(grid_size * sizeof(char)); + if (temp_grid.locations == NULL) { return NULL; } // This makes the strncat() work. - rost.rost[0] = '\0'; + temp_grid.locations[0] = '\0'; - char *line = malloc((rost.width + 2) * sizeof(char)); + char *line = malloc((temp_grid.width + 2) * sizeof(char)); if (line == NULL) { return NULL; } - for (int i = 0; i < rost.height; i++) { - if (fgets(line, rost.width + 2, fh) == NULL) { - free(rost.rost); + for (int i = 0; i < temp_grid.height; i++) { + if (fgets(line, temp_grid.width + 2, fh) == NULL) { + free(temp_grid.locations); free(line); return NULL; } // Validate that the line length is correct - if ((int)strcspn(line, "\n") != rost.width) { - free(rost.rost); + if ((int)strcspn(line, "\n") != temp_grid.width) { + free(temp_grid.locations); free(line); return NULL; } // Width is without the newline at the end. - strncat(rost.rost, line, rost.width + 1); + strncat(temp_grid.locations, line, temp_grid.width + 1); } free(line); - grid *return_grid = malloc(sizeof(rost)); + grid *return_grid = malloc(sizeof(temp_grid)); if (return_grid == NULL) { return NULL; } - memcpy(return_grid, &rost, sizeof(rost)); + memcpy(return_grid, &temp_grid, sizeof(temp_grid)); return return_grid; } @@ -192,9 +200,9 @@ void grid_put_state(grid *gp, const state t) { void grid_cleanup(grid *gp) { if (gp != NULL) { - if (gp->rost != NULL) + if (gp->locations != NULL) { - free(gp->rost); + free(gp->locations); } free(gp); } @@ -215,7 +223,7 @@ int grid_height(const grid *gp) { } int grid_contains(const grid *gp, const int x, const int y) { - if (gp != NULL && gp->rost != NULL) { + if (gp != NULL && gp->locations != NULL) { if (x >= 0 && y >= 0 && x < gp->width && y < gp->height) { return 1; @@ -225,25 +233,25 @@ int grid_contains(const grid *gp, const int x, const int y) { } char grid_fetch(const grid *gp, const int x, const int y) { - if (gp != NULL && gp->rost != NULL && grid_contains(gp, x, y) == 1) { - return gp->rost[internal_location(gp, x, y)]; + if (gp != NULL && gp->locations != NULL && grid_contains(gp, x, y) == 1) { + return gp->locations[internal_location(gp, x, y)]; } return '\0'; } int grid_put(grid *gp, const int x, const int y, const char c) { - if (gp != NULL && gp->rost != NULL && grid_contains(gp, x, y) == 1) { - gp->rost[internal_location(gp, x, y)] = c; + if (gp != NULL && gp->locations != NULL && grid_contains(gp, x, y) == 1) { + gp->locations[internal_location(gp, x, y)] = c; return 1; } return 0; } char *grid_fetch_row(const grid *gp, const int y) { - if (gp != NULL && gp->rost != NULL && grid_contains(gp, 0, y) == 1) { + if (gp != NULL && gp->locations != NULL && grid_contains(gp, 0, y) == 1) { // we're going to remove the newline so this is long enough char *row = malloc((gp->width + 1) * sizeof(char)); - memcpy(row, &gp->rost[internal_location(gp, 0, y)], gp->width * sizeof(char)); + memcpy(row, &gp->locations[internal_location(gp, 0, y)], gp->width * sizeof(char)); row[gp->width] = '\0'; return row; } @@ -251,11 +259,11 @@ char *grid_fetch_row(const grid *gp, const int y) { } grid *grid_copy(const grid *gp) { - if (gp != NULL && gp->rost != NULL) { + if (gp != NULL && gp->locations != NULL) { const size_t grid_memory = ((gp->width + 1) * gp->height + 1) * sizeof(char); - char *rost = malloc(grid_memory); - if (rost == NULL) { + char *locations = malloc(grid_memory); + if (locations == NULL) { return NULL; } @@ -264,18 +272,18 @@ grid *grid_copy(const grid *gp) { return NULL; } - memcpy(rost, gp->rost, grid_memory); + memcpy(locations, gp->locations, grid_memory); memcpy(new_grid, gp, sizeof(*gp)); - new_grid->rost = rost; + new_grid->locations = locations; return new_grid; } return NULL; } void grid_find(const grid *gp, const char c, int *x, int *y) { - if (gp == NULL || gp->rost == NULL) { + if (gp == NULL || gp->locations == NULL) { *x = -1; *y = -1; return; @@ -283,9 +291,9 @@ void grid_find(const grid *gp, const char c, int *x, int *y) { const char search[2] = {c}; - const int char_index = (int)strcspn(gp->rost, search); + const int char_index = (int)strcspn(gp->locations, search); - if (gp->rost[char_index] == '\0') + if (gp->locations[char_index] == '\0') { *x = -1; *y = -1; diff --git a/grid.h b/grid.h index 5dd800a..838834e 100644 --- a/grid.h +++ b/grid.h @@ -1,5 +1,5 @@ /* - * grid.h + * Created by snapshot112 on 2/10/2025 * * This module provides a grid api. * diff --git a/grid_game_engine.c b/grid_game_engine.c index 82958d0..3989236 100644 --- a/grid_game_engine.c +++ b/grid_game_engine.c @@ -1,7 +1,5 @@ /* - * Created by snapshot112 on 10/15/25. - * - * A game engine that can run and display games in square grids. + * Created by snapshot112 on 8/10/2025 */ #include "grid_game_engine.h" @@ -84,14 +82,13 @@ static void display_hackerman(const coordinate location) { } void graceful_exit(const coordinate message_location) { - mvaddstr(message_location.y, message_location.x, "Press ENTER or SPACE to exit."); + mvaddstr(message_location.y, message_location.x, "Press ENTER to exit."); while (1) { switch (getch()) { case KEY_BACKSPACE: case KEY_ESCAPE: case KEY_ENTER: case '\n': - case ' ': return; } } diff --git a/grid_game_engine.h b/grid_game_engine.h index 713e90f..5ba77c5 100644 --- a/grid_game_engine.h +++ b/grid_game_engine.h @@ -1,8 +1,7 @@ /* - * Created by snapshot112 on 10/15/25. + * Created by snapshot112 on 15/10/2025. * - * A game engine that uses the can run and display games in rectangular grids. - * The graphics are made using ncurses. + * A game engine build on top of a grid api to run and display games using ncurses. * * Please make sure to initialize the game engine before running any games. */ @@ -133,12 +132,12 @@ void update_grid(grid *gp, char c, int x, int y); void game_exit_message(const grid *gp, coordinate location); /* - * Waits for you to press ENTER or SPACE before exiting the game. + * Waits for you to press ENTER before exiting the game. * * Input: * coordinate: The location to show the message. * - * Side effect: Prints "Press ENTER or SPACE to exit." game to the console. + * Side effect: Prints "Press ENTER to exit." game to the console. */ void graceful_exit(coordinate message_location); diff --git a/manual.c b/manual.c index 63cab11..022663e 100644 --- a/manual.c +++ b/manual.c @@ -1,6 +1,7 @@ -// -// Created by snapshot112 on 10/17/25. -// +/* + * Created by snapshot112 on 10/17/2025 + */ + #include "manual.h" @@ -26,7 +27,7 @@ void manual(const coordinate display_location) { // Wait until ESCAPE or BACKSPACE is pressed. timeout(200); - for (int ch = getch(); ch != KEY_ESCAPE && ch != KEY_BACKSPACE && ch != ' '; ch = getch()) { + for (int ch = getch(); ch != KEY_ESCAPE && ch != KEY_BACKSPACE; ch = getch()) { // Update the screen in the meantime to accommodate windows resizes. show_grid_on_offset(grid, display_location.x, display_location.y); } diff --git a/manual.h b/manual.h index da8d146..7b24f77 100644 --- a/manual.h +++ b/manual.h @@ -1,7 +1,7 @@ /* - * Created by snapshot112 on 10/15/25. + * Created by snapshot112 on 10/17/2025 * - * Display the manual for the minigames + * Provides a way to display the minigame manual in the assets in game. */ #ifndef MINIGAME_MENU_MANUAL_H @@ -9,7 +9,7 @@ #include "grid_game_engine.h" /* - * A game manual for the minigames menu. + * An in game manual for the minigames menu. * * Please make sure to include and initialize the game engine before opening the manual * @@ -20,7 +20,7 @@ * Clears the console and uses it to display the manual. * * Controls: - * Press ESCAPE or ENTER to exit the manual. + * Press ESCAPE or BACKSPACE to exit the manual. */ void manual(coordinate display_location); diff --git a/maze_runner.c b/maze_runner.c index ca56a20..f48cc7d 100644 --- a/maze_runner.c +++ b/maze_runner.c @@ -1,6 +1,6 @@ -// -// Created by snapshot112 on 10/15/25. -// +/* + * Created by snapshot112 on 6/10/2025 + */ #include "maze_runner.h" diff --git a/maze_runner.h b/maze_runner.h index ddfbff7..a4eb7bd 100644 --- a/maze_runner.h +++ b/maze_runner.h @@ -1,9 +1,11 @@ /* + * Created by snapshot112 on 6/10/2025 + * * Naam: Jeroen Boxhoorn * UvAnetID: 16333969 - * Studie: BSc Informatica + * Studie: BSC Informatica * - * A game of maze runner configured to run on the grid game engine. + * A game of maze runner build on the grid game engine. * * Please make sure to include and initialize the game engine before calling maze_runner(); * @@ -23,7 +25,7 @@ #define MINIGAME_MENU_MAZE_RUNNER_H /* - * A game of maze runner configured to run on the grid game engine. + * A game of maze runner build on the grid game engine. * * Please make sure to include and initialize the game engine before calling maze_runner(); * @@ -32,7 +34,7 @@ * * Controls: * use WSAD or arrow keys to move through the maze. - * Use BACKSPACE to exit the game early. + * Use BACKSPACE or ESCAPE to exit the game early. */ void maze_runner(void); diff --git a/minesweeper.c b/minesweeper.c index c59858f..b20190f 100644 --- a/minesweeper.c +++ b/minesweeper.c @@ -1,6 +1,6 @@ -// -// Created by snapshot112 on 10/15/25. -// +/* + * Created by snapshot112 on 15/10/2025 + */ #include "minesweeper.h" diff --git a/minesweeper.h b/minesweeper.h index 6463556..5db4cdc 100644 --- a/minesweeper.h +++ b/minesweeper.h @@ -1,18 +1,18 @@ /* - * Created by snapshot112 on 10/15/25. + * Created by snapshot112 on 15/10/2025 * - * A game of minesweeper runner configured to run on the grid game engine. + * A game of minesweeper build on the grid game engine. * - * Please make sure to include and initialize the game engine before calling snake(); + * Please make sure to include and initialize the game engine before calling minesweeper(); */ #ifndef MINIGAME_MENU_MINESWEEPER_H #define MINIGAME_MENU_MINESWEEPER_H /* - * A game of minesweeper configured to run on the grid game engine. + * A game of minesweeper build on the grid game engine. * - * Please make sure to include and initialize the game engine before calling snake(); + * Please make sure to include and initialize the game engine before calling minesweeper(); * * Side Effects: * Clears the console and uses it to play a game of minesweeper. diff --git a/minigame_menu.c b/minigame_menu.c index 635796a..7eadefd 100644 --- a/minigame_menu.c +++ b/minigame_menu.c @@ -1,6 +1,6 @@ -// -// Created by snapshot112 on 10/15/25. -// +/* + * Created by snapshot112 on 15/10/2025 + */ #include "minigame_menu.h" @@ -152,7 +152,6 @@ static int navigate_menu(void) { } launch_game(SELECTED_GAME); break; - case 'p': case KEY_BACKSPACE: case KEY_ESCAPE: return 1; diff --git a/minigame_menu.h b/minigame_menu.h index 7800f5a..07a68e7 100644 --- a/minigame_menu.h +++ b/minigame_menu.h @@ -1,7 +1,7 @@ /* - * Created by snapshot112 on 10/15/25. + * Created by snapshot112 on 15/10/2025 * - * A minigame menu for games configured to run on the grid game engine. + * A minigame menu for games build on the grid game engine. * * Please make sure to include and initialize the game engine before calling menu(); */ @@ -10,7 +10,7 @@ #define MINIGAME_MENU_MINIGAME_MENU_H /* - * A minigame menu for games configured to run on the grid game engine. + * A minigame menu for games build on the grid game engine. * * Please make sure to include and initialize the game engine before calling menu(); * @@ -18,10 +18,10 @@ * Clears the console and uses it to display a minigame menu. * * Controls: - * 'w'/'arr_up: Next menu item. - * 's'/'arr_down': Previous menu item. - * 'f': Select current menu item. - * 'BACKSPACE': Exit the menu. + * 'w'/'arr_up': Next menu item. + * 's'/'arr_down': Previous menu item. + * 'f'/'ENTER': Select current menu item. + * 'BACKSPACE'/'ESC': Exit the menu. */ void minigame_menu(void); diff --git a/snake.c b/snake.c index 7d7a389..e2a74f3 100644 --- a/snake.c +++ b/snake.c @@ -1,6 +1,6 @@ -// -// Created by snapshot112 on 10/15/25. -// +/* + * Created by snapshot112 on 15/10/2025 + */ #define _POSIX_C_SOURCE 199309 diff --git a/snake.h b/snake.h index 21cda6b..0812b5e 100644 --- a/snake.h +++ b/snake.h @@ -1,7 +1,7 @@ /* - * Created by snapshot112 on 10/15/25. + * Created by snapshot112 on 15/10/2025 * - * A game of maze runner configured to run on the grid game engine. + * A game of maze runner build on the grid game engine. * * Please make sure to include and initialize the game engine before calling snake(); */ @@ -10,7 +10,7 @@ #define MINIGAME_MENU_SNAKE_H /* - * A game of snake configured to run on the grid game engine. + * A game of snake build on the grid game engine. * * Please make sure to include and initialize the game engine before calling snake(); * @@ -19,7 +19,7 @@ * * Controls: * Use WSAD or arrow keys to redirect the snake. - * Use BACKSPACE to exit the game early. + * Use BACKSPACE or ESCAPE to exit the game early. */ void snake(void); diff --git a/spel b/spel index df382ac..4af86fd 100755 Binary files a/spel and b/spel differ diff --git a/spel.c b/spel.c index c7123a3..8643e70 100644 --- a/spel.c +++ b/spel.c @@ -1,7 +1,9 @@ /* + * Created by snapshot112 on 15/10/2025 + * * Naam: Jeroen Boxhoorn * UvAnetID: 16333969 - * Studie: BSc Informatica + * Studie: BSC Informatica * * A minigame menu that lets you play games on the grid game engine. * @@ -9,6 +11,8 @@ * - maze runner * - snake * - minesweeper + * + * A user manual can be found in the assets or by selected it in the menu using ENTER or 'f'. */ #include "grid_game_engine.h"