Got the minigame menu up, running and documented. Also split up the game file

This commit is contained in:
2025-10-16 01:10:09 +02:00
parent 06e148a710
commit cfd4ccad64
15 changed files with 737 additions and 479 deletions

View File

@@ -4,9 +4,6 @@
#include <string.h>
#include <stdio.h>
// TODO: End the eternal NULL checks.
/*
* The rooster type this program is build around.
*/
@@ -17,14 +14,12 @@ typedef struct rooster_data {
toestand state;
} rooster;
rooster *rooster_maak(const char* input) {
int width = 0;
int height = 0;
const size_t len = strlen(input) / sizeof(char);
if (input == NULL || len == 0) {
perror("rooster_maak");
exit(1);
return NULL;
}
for (int i = 0; input[i] != '\n'; i++) {
@@ -35,14 +30,18 @@ rooster *rooster_maak(const char* input) {
for (int i = 0; i < height; i = i + width + 1) {
if ((int)strcspn(&input[i], "\n") != width) {
perror("rooster_maak");
exit(1);
};
return NULL;
}
}
const int grid_size = (width + 1) * height + 1;
rooster *rp = malloc(sizeof(rooster));
if (rp == NULL) {
return NULL;
}
rp->rost = malloc(grid_size * sizeof(char));
rp->height = height;
rp->width = width;
@@ -68,10 +67,6 @@ rooster *rooster_maak(const char* input) {
* 0 otherwise
*/
static int get_grid_sizes(FILE *fh, rooster *rost) {
if (fh == NULL) {
return 0;
}
while (getc(fh) != '\n') {
if (feof(fh)) {
return 0;
@@ -242,18 +237,6 @@ int rooster_plaats(rooster *rp, int x, int y, char c) {
return 0;
}
char *rooster_als_string(const rooster *rp) {
if (rp != NULL && rp->rost != NULL) {
char *string = malloc(sizeof(rp->rost));
if (string == NULL) {
return NULL;
}
memcpy(string, rp->rost, sizeof(rp->rost));
return string;
}
return NULL;
}
char *rooster_vraag_rij(const rooster *rp, int y) {
if (rp != NULL && rp->rost != NULL && rooster_bevat(rp, 0, y) == 1) {
// we're going to remove the newline so this is long enough