General refactor and minor improvements

This commit is contained in:
2025-10-18 18:56:28 +02:00
parent 103f85d07e
commit 6b0e858064
13 changed files with 616 additions and 466 deletions

View File

@@ -11,20 +11,19 @@
#include "manual.h"
#include "maze_runner.h"
#include "minesweeper.h"
#include "rooster.h"
#include "snake.h"
#define AMOUNT_OF_MENU_OPTIONS 5
typedef enum {
GAME_HELP = 0,
GAME_MANUAL = 0,
GAME_MAZE_RUNNER = 1,
GAME_SNAKE = 2,
GAME_MINESWEEPER = 3,
GAME_QUIT = 4,
} game;
static game SELECTED_GAME = GAME_HELP;
static game SELECTED_GAME = GAME_MANUAL;
static int OFFSET_Y = 5;
static int OFFSET_X = 5;
@@ -37,7 +36,7 @@ static int OFFSET_X = 5;
*/
static void launch_game(const game game) {
switch (game) {
case GAME_HELP:
case GAME_MANUAL:
manual((coordinate){0,0});
break;
case GAME_MAZE_RUNNER:
@@ -65,16 +64,16 @@ static void launch_game(const game game) {
* If a valid menu option is provided: It will be highlighted in green.
* If an invalid menu option is provided: Nothing happens
*/
static void menu_highlight(const rooster *menu) {
static void menu_highlight(const grid *menu) {
switch (SELECTED_GAME) {
case GAME_HELP:
case GAME_MANUAL:
case GAME_MAZE_RUNNER:
case GAME_SNAKE:
case GAME_MINESWEEPER:
case GAME_QUIT:
attron(COLOR_PAIR(GREEN));
char* row = rooster_vraag_rij(menu, SELECTED_GAME);
char* row = grid_fetch_row(menu, SELECTED_GAME);
mvprintw(OFFSET_Y + (int)SELECTED_GAME, OFFSET_X, "%s", row);
free(row);
@@ -94,7 +93,7 @@ static void menu_highlight(const rooster *menu) {
* Side Effects:
* Displays the menu
*/
static void show_menu(const rooster *menu) {
static void show_menu(const grid *menu) {
erase();
show_grid_on_offset(menu, OFFSET_X, OFFSET_Y);
menu_highlight(menu);
@@ -167,19 +166,19 @@ static int navigate_menu(void) {
* Output:
* A pointer to the menu grid.
*/
static rooster *initialize_menu(void) {
static grid *initialize_menu(void) {
char menu[] = "How to play\n"
"Maze Runner\n"
" Snake \n"
"Minesweeper\n"
" Leave \n";
rooster *rp = grid_from_string(menu);
grid *rp = grid_create_from_string(menu);
return rp;
}
void minigame_menu(void) {
rooster *menu = initialize_menu();
grid *menu = initialize_menu();
launch_game(GAME_MANUAL);
while (true) {
show_menu(menu);
if (navigate_menu() == 1) {
@@ -187,5 +186,5 @@ void minigame_menu(void) {
}
}
rooster_klaar(menu);
grid_cleanup(menu);
}