summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <Colomar.6.4.3@GMail.com>2018-08-31 16:32:58 +0200
committerGitHub <noreply@github.com>2018-08-31 16:32:58 +0200
commit6b4b886a2e0fbbcf341720a5b8e259c906919657 (patch)
tree374fb422fb28e86ac1d5e9e3807b1ac2cbe229e5
parentfe901b2e4b2dc751ff2183dbb08b9d7a391e7854 (diff)
V 3.b.1
- Levels: beginner, intermediate, expert & custom. - CLUI menu - bug fix: scanf()/getchar() substituted by fgets() & sscanf()
-rw-r--r--Makefile2
-rw-r--r--libalx/inc/alx_getnum.h4
-rw-r--r--libalx/src/alx_getnum.c60
-rw-r--r--libalx/src/alx_ncur.c2
-rw-r--r--modules/about/inc/about.h7
-rw-r--r--modules/ctrl/src/start.c5
-rw-r--r--modules/game/inc/game_iface.h28
-rw-r--r--modules/game/src/game_iface.c11
-rw-r--r--modules/menu/inc/menu_clui.h27
-rw-r--r--modules/menu/inc/menu_iface.h3
-rw-r--r--modules/menu/obj/Makefile50
-rw-r--r--modules/menu/src/menu_clui.c207
-rw-r--r--modules/menu/src/menu_iface.c47
-rw-r--r--modules/menu/src/menu_tui.c62
-rw-r--r--modules/player/src/player_clui.c43
15 files changed, 462 insertions, 96 deletions
diff --git a/Makefile b/Makefile
index af77e94..a84ac47 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
# This Makefile has parts of the linux kernel Makefile code.
VERSION = 3
PATCHLEVEL = a
-SUBLEVEL = 8
+SUBLEVEL = 10
EXTRAVERSION =
NAME = instalable
diff --git a/libalx/inc/alx_getnum.h b/libalx/inc/alx_getnum.h
index e9019f4..2f5e1d9 100644
--- a/libalx/inc/alx_getnum.h
+++ b/libalx/inc/alx_getnum.h
@@ -28,9 +28,9 @@
const char *formatB,
...);
- int64_t alx_getint (int64_t m,
+ int64_t alx_getint (double m,
int64_t def,
- int64_t M,
+ double M,
const char *formatA,
const char *formatB,
...);
diff --git a/libalx/src/alx_getnum.c b/libalx/src/alx_getnum.c
index d3f74cc..51c6347 100644
--- a/libalx/src/alx_getnum.c
+++ b/libalx/src/alx_getnum.c
@@ -22,7 +22,7 @@
static double loop_getdbl (double m, double def, double M);
-static int64_t loop_getint (int64_t m, int64_t def, int64_t M);
+static int64_t loop_getint (double m, int64_t def, double M);
static void manage_error (int err);
@@ -63,7 +63,7 @@ double alx_getdbl (double m, double def, double M,
* the number two more times. After that, it uses the default
* value.
*/
-int64_t alx_getint (int64_t m, int64_t def, int64_t M,
+int64_t alx_getint (double m, int64_t def, double M,
const char *formatA, const char *formatB, ...)
{
va_list args;
@@ -75,7 +75,7 @@ int64_t alx_getint (int64_t m, int64_t def, int64_t M,
puts(formatA);
}
if (formatB == NULL) {
- printf("Introduce an integer number [%"PRIi64" U %"PRIi64"] (default %"PRIi64"):...\t", m, M, def);
+ printf("Introduce an integer number [%lf U %lf] (default %"PRIi64"):...\t", m, M, def);
} else {
vprintf(formatB, args);
}
@@ -91,26 +91,21 @@ static double loop_getdbl (double m, double def, double M)
{
int i;
char buff [BUFF_SIZE];
- char *x1;
- int x2;
+ char *x;
double R;
int err;
for (i = 0; i < MAX_TRIES; i++) {
- x1 = fgets(buff, BUFF_SIZE, stdin);
-
- if (x1 == NULL) {
- err = ERR_FGETS;
+ x = fgets(buff, BUFF_SIZE, stdin);
+
+ if (x == NULL) {
+ err = ERR_FGETS;
+ } else if (sscanf(buff, "%lf", &R) != 1) {
+ err = ERR_SSCANF;
+ } else if (R < m || R > M) {
+ err = ERR_RANGE;
} else {
- x2 = sscanf(buff, "%lf", &R);
-
- if (x2 != 1) {
- err = ERR_SSCANF;
- } else if (R < m || R > M) {
- err = ERR_RANGE;
- } else {
- break;
- }
+ break;
}
manage_error(err);
@@ -120,34 +115,29 @@ static double loop_getdbl (double m, double def, double M)
return R;
}
-static int64_t loop_getint (int64_t m, int64_t def, int64_t M)
+static int64_t loop_getint (double m, int64_t def, double M)
{
int i;
char buff [BUFF_SIZE];
- char *x1;
- int x2;
+ char *x;
int64_t Z;
int err;
for (i = 0; i < MAX_TRIES; i++) {
- x1 = fgets(buff, BUFF_SIZE, stdin);
-
- if (x1 == NULL) {
- err = ERR_FGETS;
+ x = fgets(buff, BUFF_SIZE, stdin);
+
+ if (x == NULL) {
+ err = ERR_FGETS;
+ } else if (sscanf(buff, "%"SCNi64, &Z) != 1) {
+ err = ERR_SSCANF;
+ } else if (Z < m || Z > M) {
+ err = ERR_RANGE;
} else {
- x2 = sscanf(buff, "%"SCNi64, &Z);
-
- if (x2 != 1) {
- err = ERR_SSCANF;
- } else if (Z < m || Z > M) {
- err = ERR_RANGE;
- } else {
- break;
- }
+ break;
}
manage_error(err);
- Z = def;
+ Z = def;
}
return Z;
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c
index c615c56..dd86eea 100644
--- a/libalx/src/alx_ncur.c
+++ b/libalx/src/alx_ncur.c
@@ -422,7 +422,7 @@ void alx_ncur_prn_title (WINDOW *win, const char *title)
len = strlen(title);
/* Print title centered */
- mvwaddch(win, 0, (w - len)/2 - 1, ACS_RTEE);
+ mvwaddch(win, 0, (w - (len + 2))/2 - 1, ACS_RTEE);
wprintw(win, " %s ", title);
waddch(win, ACS_LTEE);
diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h
index 9a3de85..b40ae2f 100644
--- a/modules/about/inc/about.h
+++ b/modules/about/inc/about.h
@@ -11,6 +11,13 @@
/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+ /* FILENAME_MAX */
+ #include <stdio.h>
+
+
+/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
# define PROG_NAME "mine_sweeper"
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c
index f80067b..eb464f2 100644
--- a/modules/ctrl/src/start.c
+++ b/modules/ctrl/src/start.c
@@ -75,10 +75,11 @@ static void start_foo (void)
static void start_rand (void)
{
/* size & mines */
+ int level;
int rows;
int cols;
int mines;
- menu_iface_board(&rows, &cols, &mines);
+ menu_iface_board(&level, &rows, &cols, &mines);
/* user iface init */
player_iface_init(rows, cols);
@@ -92,7 +93,7 @@ static void start_rand (void)
game_init_rand(rows, cols, mines, r, c);
/* game iface init */
- game_iface_init_rand(r, c);
+ game_iface_init_rand(level, r, c);
/* game loop */
game_iface();
diff --git a/modules/game/inc/game_iface.h b/modules/game/inc/game_iface.h
index 3bb1ebd..8f596bf 100644
--- a/modules/game/inc/game_iface.h
+++ b/modules/game/inc/game_iface.h
@@ -13,14 +13,33 @@
/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
- # define ROWS_MAX (22)
- # define COLS_MAX (33)
- # define CHEATED (-1)
+ # define ROWS_MAX (999)
+ # define COLS_MAX (999)
+ # define CHEATED (-1)
+
+ # define GAME_IFACE_LEVEL_BEGINNER_ROWS (8)
+ # define GAME_IFACE_LEVEL_BEGINNER_COLS (8)
+ # define GAME_IFACE_LEVEL_BEGINNER_MINES (10)
+
+ # define GAME_IFACE_LEVEL_INTERMEDIATE_ROWS (16)
+ # define GAME_IFACE_LEVEL_INTERMEDIATE_COLS (16)
+ # define GAME_IFACE_LEVEL_INTERMEDIATE_MINES (40)
+
+ # define GAME_IFACE_LEVEL_EXPERT_ROWS (16)
+ # define GAME_IFACE_LEVEL_EXPERT_COLS (30)
+ # define GAME_IFACE_LEVEL_EXPERT_MINES (99)
/******************************************************************************
******* enums ****************************************************************
******************************************************************************/
+ enum Game_Iface_Level {
+ GAME_IFACE_LEVEL_BEGINNER = 0,
+ GAME_IFACE_LEVEL_INTERMEDIATE,
+ GAME_IFACE_LEVEL_EXPERT,
+ GAME_IFACE_LEVEL_CUSTOM
+ };
+
enum Game_Iface_Visible_Board {
GAME_IFACE_VIS_KBOOM,
GAME_IFACE_VIS_HIDDEN_FIELD,
@@ -100,6 +119,7 @@
};
struct Game_Iface_Score {
+ int level;
int time;
int clicks;
};
@@ -113,7 +133,7 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void game_iface_init_rand (int pos_row, int pos_col);
+ void game_iface_init_rand (int level, int pos_row, int pos_col);
void game_iface_init_load (void);
void game_iface (void);
diff --git a/modules/game/src/game_iface.c b/modules/game/src/game_iface.c
index f7b35fb..94a84ea 100644
--- a/modules/game/src/game_iface.c
+++ b/modules/game/src/game_iface.c
@@ -42,7 +42,7 @@ static time_t tim_ini;
******* static functions *****************************************************
******************************************************************************/
/* Init */
-static void game_iface_init_score (void);
+static void game_iface_init_score (int level);
static void game_iface_init_cheated (void);
/* Actions */
static void game_iface_act (void);
@@ -73,13 +73,13 @@ static void game_iface_clean_in (void);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void game_iface_init_rand (int pos_row, int pos_col)
+void game_iface_init_rand (int level, int pos_row, int pos_col)
{
/* first step */
game_action(GAME_ACT_STEP, pos_row, pos_col);
game_iface_out.state = GAME_IFACE_STATE_PLAYING;
- game_iface_init_score();
+ game_iface_init_score(level);
game_iface_out.rows = game_board.rows;
game_iface_out.cols = game_board.cols;
@@ -118,8 +118,9 @@ void game_iface (void)
/* * * * * * * * * *
* * * Init * * * * * * *
* * * * * * * * * */
-static void game_iface_init_score (void)
+static void game_iface_init_score (int level)
{
+ game_iface_score.level = level;
tim_ini = time(NULL);
game_iface_score.clicks = 1;
}
@@ -127,6 +128,7 @@ static void game_iface_init_score (void)
static void game_iface_init_cheated (void)
{
game_iface_out.state = GAME_IFACE_STATE_CHEATED;
+ game_iface_score.level = GAME_IFACE_LEVEL_CUSTOM;
game_iface_score.time = CHEATED;
game_iface_score.clicks = CHEATED;
}
@@ -486,6 +488,7 @@ static void game_iface_update_score (void)
case GAME_IFACE_STATE_XYZZY:
case GAME_IFACE_STATE_CHEATED:
+ game_iface_score.level = GAME_IFACE_LEVEL_CUSTOM;
game_iface_score.time = CHEATED;
game_iface_score.clicks = CHEATED;
break;
diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h
new file mode 100644
index 0000000..fb3d20f
--- /dev/null
+++ b/modules/menu/inc/menu_clui.h
@@ -0,0 +1,27 @@
+/******************************************************************************
+ * Copyright (C) 2015 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef MSW_MENU_CLUI_H
+ # define MSW_MENU_CLUI_H
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void menu_clui (void);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* menu_clui.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h
index 22a61d0..a7ac23b 100644
--- a/modules/menu/inc/menu_iface.h
+++ b/modules/menu/inc/menu_iface.h
@@ -31,6 +31,7 @@
******* structs **************************************************************
******************************************************************************/
struct Menu_Iface_Variables {
+ int level;
int rows;
int cols;
double p;
@@ -49,7 +50,7 @@ extern struct Menu_Iface_Variables menu_iface_variables;
******* functions ************************************************************
******************************************************************************/
void menu_iface_init (void);
-void menu_iface_board (int *rows, int *cols, int *mines);
+void menu_iface_board (int *level, int *rows, int *cols, int *mines);
void menu_iface (void);
diff --git a/modules/menu/obj/Makefile b/modules/menu/obj/Makefile
index 549869d..3195384 100644
--- a/modules/menu/obj/Makefile
+++ b/modules/menu/obj/Makefile
@@ -17,7 +17,7 @@ SRC_DIR = $(MENU_DIR)/src/
# dependencies
-_ALL = parser.o menu_iface.o menu_tui.o
+_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o
ALL = $(_ALL) menu_mod.o
PARS_INC_LIBALX = alx_seed.h
@@ -44,39 +44,54 @@ PARS_INC_DIRS = -I $(INC_DIR) \
-I $(SAVE_INC_DIR)
MENUI_INC_CTRL = start.h
-MENUI_INC = menu_iface.h menu_tui.h #menu_clui.h
+MENUI_INC_GAME = game_iface.h
+MENUI_INC = menu_iface.h menu_clui.h menu_tui.h
MENUI_DEPS = $(SRC_DIR)/menu_iface.c \
$(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) \
- $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUI_INC_CTRL))
+ $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUI_INC_CTRL)) \
+ $(patsubst %,$(GAME_INC_DIR)/%,$(MENUI_INC_GAME))
MENUI_INC_DIRS = -I $(INC_DIR) \
- -I $(CTRL_INC_DIR)
-
-#MENUCLUI_INC_LIBALX =
-#MENUCLUI_INC_DATA = data.h
-#MENUCLUI_INC = game_clui.h
-#MENUCLUI_DEPS = $(SRC_DIR)/game_clui.c \
-# $(patsubst %,$(INC_DIR)/%,$(MENUCLUI_INC)) \
-# $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUCLUI_INC_LIBALX)) \
-# $(patsubst %,$(DATA_INC_DIR)/%,$(MENUCLUI_INC_DATA))
-#MENUCLUI_INC_DIRS = -I $(INC_DIR) \
-# -I $(LIBALX_INC_DIR) \
-# -I $(DATA_INC_DIR)
+ -I $(CTRL_INC_DIR) \
+ -I $(GAME_INC_DIR)
+
+MENUCLUI_INC_LIBALX = alx_getnum.h
+MENUCLUI_INC_ABOUT = about.h
+MENUCLUI_INC_CTRL = start.h
+MENUCLUI_INC_GAME = game_iface.h
+MENUCLUI_INC_SAVE = save.h
+MENUCLUI_INC = menu_clui.h menu_iface.h
+MENUCLUI_DEPS = $(SRC_DIR)/menu_clui.c \
+ $(patsubst %,$(INC_DIR)/%,$(MENUCLUI_INC)) \
+ $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUCLUI_INC_LIBALX)) \
+ $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUCLUI_INC_ABOUT)) \
+ $(patsubst %,$(GAME_INC_DIR)/%,$(MENUCLUI_INC_GAME)) \
+ $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUCLUI_INC_CTRL)) \
+ $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUCLUI_INC_SAVE))
+MENUCLUI_INC_DIRS = -I $(INC_DIR) \
+ -I $(LIBALX_INC_DIR) \
+ -I $(ABOUT_INC_DIR) \
+ -I $(CTRL_INC_DIR) \
+ -I $(GAME_INC_DIR) \
+ -I $(SAVE_INC_DIR)
MENUTUI_INC_LIBALX = alx_ncur.h
MENUTUI_INC_ABOUT = about.h
MENUTUI_INC_CTRL = start.h
+MENUTUI_INC_GAME = game_iface.h
MENUTUI_INC_SAVE = save.h
MENUTUI_INC = menu_tui.h menu_iface.h
MENUTUI_DEPS = $(SRC_DIR)/menu_tui.c \
$(patsubst %,$(INC_DIR)/%,$(MENUTUI_INC)) \
$(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUTUI_INC_LIBALX)) \
$(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUTUI_INC_ABOUT)) \
+ $(patsubst %,$(GAME_INC_DIR)/%,$(MENUTUI_INC_GAME)) \
$(patsubst %,$(CTRL_INC_DIR)/%,$(MENUTUI_INC_CTRL)) \
$(patsubst %,$(SAVE_INC_DIR)/%,$(MENUTUI_INC_SAVE))
MENUTUI_INC_DIRS = -I $(INC_DIR) \
-I $(LIBALX_INC_DIR) \
-I $(ABOUT_INC_DIR) \
-I $(CTRL_INC_DIR) \
+ -I $(GAME_INC_DIR) \
-I $(SAVE_INC_DIR)
# target: dependencies
@@ -101,6 +116,11 @@ menu_iface.o: $(MENUI_DEPS)
@echo "\tCC $<"
@echo ""
+menu_clui.o: $(MENUCLUI_DEPS)
+ $(Q)$(CC) $(CFLAGS) $(MENUCLUI_INC_DIRS) -c $< -o $@ $(LIBS)
+ @echo "\tCC $<"
+ @echo ""
+
menu_tui.o: $(MENUTUI_DEPS)
$(Q)$(CC) $(CFLAGS) $(MENUTUI_INC_DIRS) -c $< -o $@ $(LIBS)
@echo "\tCC $<"
diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c
new file mode 100644
index 0000000..e0b03b0
--- /dev/null
+++ b/modules/menu/src/menu_clui.c
@@ -0,0 +1,207 @@
+/******************************************************************************
+ * Copyright (C) 2015 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* * * * * * * * * *
+ * * * Standard * * * * * *
+ * * * * * * * * * */
+ /* INFINITY */
+ #include <math.h>
+ /* srand() */
+ #include <stdlib.h>
+
+/* * * * * * * * * *
+ * * * Other * * * * * * *
+ * * * * * * * * * */
+ #include "alx_getnum.h"
+
+ #include "about.h"
+ #include "game_iface.h"
+// #include "save.h"
+ #include "start.h"
+
+ #include "menu_iface.h"
+
+ #include "menu_clui.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define ROWS_CLUI_MAX (99)
+#if (ROWS_CLUI_MAX > ROWS_MAX)
+# error "rows max (clui)"
+#endif
+
+ # define COLS_CLUI_MAX (99)
+#if (COLS_CLUI_MAX > COLS_MAX)
+# error "cols max (clui)"
+#endif
+
+ # define BUFF_SIZE (1024)
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void menu_clui_rand (void);
+static void menu_clui_custom (void);
+static void menu_clui_load (void);
+static void menu_clui_start (void);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void menu_clui (void)
+{
+ char buff [BUFF_SIZE];
+ char ch;
+
+ ch = 'n';
+ printf("Read 'Disclaimer of warranty'? (yes/NO): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ if (ch == 'y' || ch == 'Y') {
+ puts (" >yes");
+ print_disclaim();
+ } else {
+ puts (" >NO");
+ }
+
+ ch = 'n';
+ printf("Read 'License'? (yes/NO): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ if (ch == 'y' || ch == 'Y') {
+ puts (" >yes");
+ print_license();
+ } else {
+ puts (" >NO");
+ }
+#if 0
+ printf("Game interface? (NCURSES/text): ");
+ scanf(" %c%*s ", &ch);
+ if (ch == 't' || ch == 'T') {
+ puts (" >text");
+ // FIXME
+ } else {
+ puts (" >NCURSES");
+ // FIXME
+ }
+#endif
+ ch = 'n';
+ printf("New game or load game? (NEW/load): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ if (ch == 'l' || ch == 'L') {
+ puts (" >load");
+ menu_clui_load();
+ } else {
+ puts (" >NEW");
+ menu_clui_rand();
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void menu_clui_rand (void)
+{
+ /* Random */
+ start_mode = START_RAND;
+
+ char buff [BUFF_SIZE];
+ char ch;
+
+ ch = 'n';
+ printf("Set seed for random generator? (yes/NO): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ int seed;
+ if (ch == 'y' || ch == 'Y') {
+ puts (" >yes");
+ seed = alx_getint(-INFINITY, 1, INFINITY, "Seed:", NULL);
+ srand(seed);
+ } else {
+ puts (" >NO");
+ }
+
+ ch = 'b';
+ printf("Level? (BEGINNER/intermediate/expert/custom): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ if (ch == 'i' || ch == 'I') {
+ puts (" >intermediate");
+ menu_iface_variables.level = GAME_IFACE_LEVEL_INTERMEDIATE;
+ menu_clui_start();
+ } else if (ch == 'e' || ch == 'E') {
+ puts (" >expert");
+ menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT;
+ menu_clui_start();
+ } else if (ch == 'c' || ch == 'C') {
+ puts (" >custom");
+ menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM;
+ menu_clui_custom();
+ } else {
+ puts (" >BEGINNER");
+ menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER;
+ menu_clui_start();
+ }
+}
+
+static void menu_clui_custom (void)
+{
+ /* Random */
+ start_mode = START_RAND;
+
+ menu_iface_variables.rows = alx_getint(2, menu_iface_variables.rows, ROWS_CLUI_MAX, "Rows:", NULL);
+ menu_iface_variables.cols = alx_getint(2, menu_iface_variables.cols, COLS_CLUI_MAX, "Columns:", NULL);
+ menu_iface_variables.p = alx_getdbl(0, menu_iface_variables.p, 1, "Proportion:", NULL);
+
+ menu_clui_start();
+}
+
+static void menu_clui_load (void)
+{
+ /* Load */
+ start_mode = START_LOAD;
+#if 0
+ /* File name */ // FIXME
+ alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL);
+#endif
+ menu_clui_start();
+}
+
+static void menu_clui_start (void)
+{
+ puts(" >>START:");
+ start_switch();
+
+ char buff [BUFF_SIZE];
+ char ch;
+
+ ch = 'm';
+ printf("Play again? (MENU/play/exit): ");
+ fgets(buff, BUFF_SIZE, stdin);
+ sscanf(buff, " %c", &ch);
+ if (ch == 'p' || ch == 'P') {
+ puts (" >play");
+ menu_clui_start();
+ } else if (ch == 'e' || ch == 'E') {
+ puts (" >exit!");
+ } else {
+ puts (" >MENU");
+ menu_clui();
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c
index 0c95eb4..aeaa7b3 100644
--- a/modules/menu/src/menu_iface.c
+++ b/modules/menu/src/menu_iface.c
@@ -15,9 +15,10 @@
/* * * * * * * * * *
* * * Other * * * * * * *
* * * * * * * * * */
+ #include "game_iface.h"
#include "start.h"
-// #include "menu_clui.h"
+ #include "menu_clui.h"
#include "menu_tui.h"
#include "menu_iface.h"
@@ -36,22 +37,45 @@ struct Menu_Iface_Variables menu_iface_variables;
******************************************************************************/
void menu_iface_init (void)
{
+ menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER;
menu_iface_variables.rows = 8;
menu_iface_variables.cols = 8;
menu_iface_variables.p = 0.16;
}
-void menu_iface_board (int *rows, int *cols, int *mines)
+void menu_iface_board (int *level, int *rows, int *cols, int *mines)
{
- *rows = menu_iface_variables.rows;
- *cols = menu_iface_variables.cols;
-
- /* calc number of mines */
- *mines = menu_iface_variables.p * (*rows) * (*cols);
-
- /* at least one safe field */
- if ((*mines) == (*rows) * (*cols)) {
- (*mines)--;
+ *level = menu_iface_variables.level;
+
+ /* size & number of mines */
+ switch (*level) {
+ case GAME_IFACE_LEVEL_BEGINNER:
+ *rows = GAME_IFACE_LEVEL_BEGINNER_ROWS;
+ *cols = GAME_IFACE_LEVEL_BEGINNER_COLS;
+ *mines = GAME_IFACE_LEVEL_BEGINNER_MINES;
+ break;
+
+ case GAME_IFACE_LEVEL_INTERMEDIATE:
+ *rows = GAME_IFACE_LEVEL_INTERMEDIATE_ROWS;
+ *cols = GAME_IFACE_LEVEL_INTERMEDIATE_COLS;
+ *mines = GAME_IFACE_LEVEL_INTERMEDIATE_MINES;
+ break;
+
+ case GAME_IFACE_LEVEL_EXPERT:
+ *rows = GAME_IFACE_LEVEL_EXPERT_ROWS;
+ *cols = GAME_IFACE_LEVEL_EXPERT_COLS;
+ *mines = GAME_IFACE_LEVEL_EXPERT_MINES;
+ break;
+
+ case GAME_IFACE_LEVEL_CUSTOM:
+ *rows = menu_iface_variables.rows;
+ *cols = menu_iface_variables.cols;
+ *mines = menu_iface_variables.p * (*rows) * (*cols);
+ /* at least one safe field */
+ if ((*mines) == (*rows) * (*cols)) {
+ (*mines)--;
+ }
+ break;
}
}
@@ -65,6 +89,7 @@ void menu_iface (void)
break;
case MENU_IFACE_CLUI:
+ menu_clui();
break;
case MENU_IFACE_TUI:
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c
index d77f1f6..fd23491 100644
--- a/modules/menu/src/menu_tui.c
+++ b/modules/menu/src/menu_tui.c
@@ -13,6 +13,7 @@
#include <math.h>
#include <ncurses.h>
#include <stdbool.h>
+ /* srand() */
#include <stdlib.h>
/* * * * * * * * * *
@@ -21,6 +22,7 @@
#include "alx_ncur.h"
#include "about.h"
+ #include "game_iface.h"
#include "save.h"
#include "start.h"
@@ -33,7 +35,14 @@
******* macros ***************************************************************
******************************************************************************/
# define ROWS_TUI_MAX (22)
+#if (ROWS_TUI_MAX > ROWS_MAX)
+# error "rows max (tui)"
+#endif
+
# define COLS_TUI_MAX (33)
+#if (COLS_TUI_MAX > COLS_MAX)
+# error "cols max (tui)"
+#endif
/******************************************************************************
@@ -41,7 +50,8 @@
******************************************************************************/
static void menu_tui_continue (void);
static void menu_tui_select (void);
-static void menu_tui_difficulty (void);
+static void menu_tui_level (void);
+static void menu_tui_custom (void);
static void menu_tui_devel (void);
static void menu_tui_verbose (void);
@@ -170,7 +180,7 @@ static void menu_tui_continue (void)
case 3:
alx_win_del(win);
- menu_tui_difficulty();
+ menu_tui_level();
break;
case 4:
@@ -228,7 +238,51 @@ static void menu_tui_select (void)
}
-static void menu_tui_difficulty (void)
+static void menu_tui_level (void)
+{
+ /* Menu dimensions & options */
+ WINDOW *win;
+ int h;
+ int w;
+ h = 10;
+ w = 70;
+ int N;
+ N = 5;
+ struct alx_optn mnu[5] = {
+ {7, 4, "[0] Back"},
+ {2, 4, "[1] Beginner"},
+ {3, 4, "[2] Intermediate"},
+ {4, 4, "[3] Expert"},
+ {5, 4, "[4] Custom"}
+ };
+
+ /* Menu loop */
+ int sw;
+ sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:");
+
+ /* Selection */
+ switch (sw) {
+ case 1:
+ menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER;
+ break;
+
+ case 2:
+ menu_iface_variables.level = GAME_IFACE_LEVEL_INTERMEDIATE;
+ break;
+
+ case 3:
+ menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT;
+ break;
+
+ case 4:
+ menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM;
+ menu_tui_custom();
+ break;
+ }
+
+}
+
+static void menu_tui_custom (void)
{
/* Menu dimensions & options */
WINDOW *win;
@@ -274,7 +328,7 @@ static void menu_tui_difficulty (void)
wrefresh(win);
/* Selection */
- sw = alx_menu_2(win, N, mnu, "Difficulty:");
+ sw = alx_menu_2(win, N, mnu, "Custom:");
switch (sw) {
case 0:
diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c
index b195d12..a9347ee 100644
--- a/modules/player/src/player_clui.c
+++ b/modules/player/src/player_clui.c
@@ -27,6 +27,12 @@
/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define BUFF_SIZE (1024)
+
+
+/******************************************************************************
******* variables ************************************************************
******************************************************************************/
static int oldaction;
@@ -281,19 +287,24 @@ static char set_char (int game_iface_visible)
* * * * * * * * * */
static int usr_input (void)
{
- wchar_t ch;
- ch = getchar();
+ /* Wait for input */
+ char buff [BUFF_SIZE];
+ char ch;
+ buff[0] = '\0';
+ ch = '\0';
+ fgets(buff, BUFF_SIZE, stdin);
+ /* Interpret input */
int action;
-
+ sscanf(buff, "%c", &ch);
switch (ch) {
- /* Escape sequence */
+ /* Escape sequence */
case 27:
- /* Arrows ¿? */
- ch = getchar();
+ /* Arrows */
+ sscanf(buff, "%*c""%c", &ch);
switch (ch) {
case 91:
- ch = getchar();
+ sscanf(buff, "%*2c""%c", &ch);
switch (ch) {
case 65:
action = PLAYER_IFACE_ACT_MOVE_UP;
@@ -359,17 +370,17 @@ static int usr_input (void)
case 'x':
/* Special sequence "xyzzy" */
- ch = getchar();
+ sscanf(buff, "%*c""%c", &ch);
if (ch == 'y') {
- ch = getchar();
+ sscanf(buff, "%*2c""%c", &ch);
+ if (ch == 'z') {
+ sscanf(buff, "%*3c""%c", &ch);
if (ch == 'z') {
- ch = getchar();
- if (ch == 'z') {
- ch = getchar();
- if (ch == 'y') {
- action = PLAYER_IFACE_ACT_XYZZY_ON;
- }
- }
+ sscanf(buff, "%*4c""%c", &ch);
+ if (ch == 'y') {
+ action = PLAYER_IFACE_ACT_XYZZY_ON;
+ }
+ }
}
}
break;