forked from snapshot112/minigame-menu
manual??? and refactoring
This commit is contained in:
@@ -8,14 +8,23 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "grid_game_engine.h"
|
||||
#include "manual.h"
|
||||
#include "maze_runner.h"
|
||||
#include "minesweeper.h"
|
||||
#include "rooster.h"
|
||||
#include "snake.h"
|
||||
|
||||
#define AMOUNT_OF_MENU_OPTIONS 4
|
||||
#define AMOUNT_OF_MENU_OPTIONS 5
|
||||
|
||||
static game SELECTED_GAME = GAME_MAZE_RUNNER;
|
||||
typedef enum {
|
||||
GAME_HELP = 0,
|
||||
GAME_MAZE_RUNNER = 1,
|
||||
GAME_SNAKE = 2,
|
||||
GAME_MINESWEEPER = 3,
|
||||
GAME_QUIT = 4,
|
||||
} game;
|
||||
|
||||
static game SELECTED_GAME = GAME_HELP;
|
||||
static int OFFSET_Y = 5;
|
||||
static int OFFSET_X = 5;
|
||||
|
||||
@@ -28,6 +37,9 @@ static int OFFSET_X = 5;
|
||||
*/
|
||||
static void launch_game(const game game) {
|
||||
switch (game) {
|
||||
case GAME_HELP:
|
||||
manual((coordinate){0,0});
|
||||
break;
|
||||
case GAME_MAZE_RUNNER:
|
||||
maze_runner();
|
||||
break;
|
||||
@@ -55,6 +67,7 @@ static void launch_game(const game game) {
|
||||
*/
|
||||
static void menu_highlight(const rooster *menu) {
|
||||
switch (SELECTED_GAME) {
|
||||
case GAME_HELP:
|
||||
case GAME_MAZE_RUNNER:
|
||||
case GAME_SNAKE:
|
||||
case GAME_MINESWEEPER:
|
||||
@@ -82,7 +95,7 @@ static void menu_highlight(const rooster *menu) {
|
||||
* Displays the menu
|
||||
*/
|
||||
static void show_menu(const rooster *menu) {
|
||||
clear();
|
||||
erase();
|
||||
show_grid_on_offset(menu, OFFSET_X, OFFSET_Y);
|
||||
menu_highlight(menu);
|
||||
refresh();
|
||||
@@ -118,7 +131,7 @@ static void menu_move(const int offset) {
|
||||
* Side Effect:
|
||||
* Changes the SELECTED_GAME as needed and launches selected games on select.
|
||||
*/
|
||||
static int navigate_menu(rooster *menu) {
|
||||
static int navigate_menu(void) {
|
||||
switch (getch()) {
|
||||
case KEY_UP:
|
||||
case 'w':
|
||||
@@ -134,12 +147,15 @@ static int navigate_menu(rooster *menu) {
|
||||
case '\n':
|
||||
case 'f':
|
||||
case 'F':
|
||||
case ' ':
|
||||
if (SELECTED_GAME == GAME_QUIT) {
|
||||
return 1;
|
||||
}
|
||||
launch_game(SELECTED_GAME);
|
||||
break;
|
||||
case 'p':
|
||||
case KEY_BACKSPACE:
|
||||
case KEY_ESCAPE:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -152,7 +168,8 @@ static int navigate_menu(rooster *menu) {
|
||||
* A pointer to the menu grid.
|
||||
*/
|
||||
static rooster *initialize_menu(void) {
|
||||
char menu[] = "Maze Runner\n"
|
||||
char menu[] = "How to play\n"
|
||||
"Maze Runner\n"
|
||||
" Snake \n"
|
||||
"Minesweeper\n"
|
||||
" Leave \n";
|
||||
@@ -165,7 +182,7 @@ void minigame_menu(void) {
|
||||
|
||||
while (true) {
|
||||
show_menu(menu);
|
||||
if (navigate_menu(menu) == 1) {
|
||||
if (navigate_menu() == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user