diff options
author | alex <alex@ASUS> | 2018-09-01 20:38:01 +0200 |
---|---|---|
committer | alex <alex@ASUS> | 2018-09-01 20:38:01 +0200 |
commit | b044e6f99dc6fdbc6609f5c4d05ec5d05cc22929 (patch) | |
tree | 0da71024ab34270d09370b42a2b8955baf6ceede | |
parent | 40635f9bb94770e1c6d281b945603c565ae5a916 (diff) |
Modify player CLUI to show help in two lines
-rw-r--r-- | modules/ctrl/src/start.c | 33 | ||||
-rw-r--r-- | modules/game/inc/game_iface.h | 1 | ||||
-rw-r--r-- | modules/menu/src/menu_clui.c | 7 | ||||
-rw-r--r-- | modules/menu/src/menu_iface.c | 6 | ||||
-rw-r--r-- | modules/player/inc/player_iface.h | 2 | ||||
-rw-r--r-- | modules/player/src/player_clui.c | 203 | ||||
-rw-r--r-- | modules/player/src/player_iface.c | 21 |
7 files changed, 79 insertions, 194 deletions
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index eb464f2..cad72c9 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -11,8 +11,6 @@ * * * * * * * * * */
/* errno */
#include <errno.h>
- /* fflush(stdout) */
- #include <stdio.h>
/* * * * * * * * * *
* * * Other * * * * * * *
@@ -82,25 +80,27 @@ static void start_rand (void) menu_iface_board(&level, &rows, &cols, &mines);
/* user iface init */
+ bool fail;
player_iface_init(rows, cols);
/* start position */
int r;
int c;
- player_iface_start(&r, &c);
+ fail = player_iface_start(&r, &c);
- /* game init */
- game_init_rand(rows, cols, mines, r, c);
+ if (!fail) {
+ /* game init */
+ game_init_rand(rows, cols, mines, r, c);
- /* game iface init */
- game_iface_init_rand(level, r, c);
+ /* game iface init */
+ game_iface_init_rand(level, r, c);
- /* game loop */
- game_iface();
+ /* game loop */
+ game_iface();
+ }
/* user iface cluanup */
player_iface_cleanup();
- fflush(stdout);
}
static void start_load (void)
@@ -110,20 +110,19 @@ static void start_load (void) int cols;
game_init_load(&rows, &cols);
- /* player iface init */
- player_iface_init(rows, cols);
-
if (!errno) {
+ /* player iface init */
+ player_iface_init(rows, cols);
+
/* game iface init */
game_iface_init_load();
/* game loop */
game_iface();
- }
- /* user iface cluanup */
- player_iface_cleanup();
- fflush(stdout);
+ /* user iface cluanup */
+ player_iface_cleanup();
+ }
}
diff --git a/modules/game/inc/game_iface.h b/modules/game/inc/game_iface.h index 8f596bf..a920e99 100644 --- a/modules/game/inc/game_iface.h +++ b/modules/game/inc/game_iface.h @@ -37,6 +37,7 @@ GAME_IFACE_LEVEL_BEGINNER = 0,
GAME_IFACE_LEVEL_INTERMEDIATE,
GAME_IFACE_LEVEL_EXPERT,
+ GAME_IFACE_LEVEL_EXPERT_INV,
GAME_IFACE_LEVEL_CUSTOM
};
diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index e0b03b0..03c92d9 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -37,7 +37,7 @@ # error "rows max (clui)"
#endif
- # define COLS_CLUI_MAX (99)
+ # define COLS_CLUI_MAX (26)
#if (COLS_CLUI_MAX > COLS_MAX)
# error "cols max (clui)"
#endif
@@ -133,7 +133,7 @@ static void menu_clui_rand (void) }
ch = 'b';
- printf("Level? (BEGINNER/intermediate/expert/custom): ");
+ printf("Level? (BEGINNER/intermediate/(expert)/custom): ");
fgets(buff, BUFF_SIZE, stdin);
sscanf(buff, " %c", &ch);
if (ch == 'i' || ch == 'I') {
@@ -142,8 +142,9 @@ static void menu_clui_rand (void) menu_clui_start();
} else if (ch == 'e' || ch == 'E') {
puts (" >expert");
- menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT;
+ menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT_INV;
menu_clui_start();
+
} else if (ch == 'c' || ch == 'C') {
puts (" >custom");
menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM;
diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index aeaa7b3..3394293 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -67,6 +67,12 @@ void menu_iface_board (int *level, int *rows, int *cols, int *mines) *mines = GAME_IFACE_LEVEL_EXPERT_MINES;
break;
+ case GAME_IFACE_LEVEL_EXPERT_INV:
+ *rows = GAME_IFACE_LEVEL_EXPERT_COLS;
+ *cols = GAME_IFACE_LEVEL_EXPERT_ROWS;
+ *mines = GAME_IFACE_LEVEL_EXPERT_MINES;
+ break;
+
case GAME_IFACE_LEVEL_CUSTOM:
*rows = menu_iface_variables.rows;
*cols = menu_iface_variables.cols;
diff --git a/modules/player/inc/player_iface.h b/modules/player/inc/player_iface.h index ac61d39..2430002 100644 --- a/modules/player/inc/player_iface.h +++ b/modules/player/inc/player_iface.h @@ -73,7 +73,7 @@ extern int player_iface_mode; ******* functions ************************************************************
******************************************************************************/
void player_iface_init (int rows, int cols);
-void player_iface_start (int *pos_row, int *pos_col);
+int player_iface_start (int *pos_row, int *pos_col);
void player_iface (const struct Game_Iface_Out *game_iface_out,
const struct Game_Iface_Score *game_iface_score,
struct Game_Iface_In *game_iface_in);
diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c index d4742cb..fb3f6a5 100644 --- a/modules/player/src/player_clui.c +++ b/modules/player/src/player_clui.c @@ -129,13 +129,12 @@ static void show_board_start(const struct Player_Iface_Position *position, {
/* Title */
puts("________________________________________________________________________________");
- puts(title);
/* Board */
board_loop_start(position);
- /* Subtitle */
- puts(subtitle);
+ /* Subtitle & title */
+ printf("%s - %s\n", subtitle, title);
puts("--------------------------------------------------------------------------------");
}
@@ -174,15 +173,13 @@ static void show_board (const struct Game_Iface_Out *board, const char *title,
const char *subtitle)
{
- /* Title */
puts("________________________________________________________________________________");
- puts(title);
/* Board */
board_loop(board, position);
- /* Subtitle */
- puts(subtitle);
+ /* Subtitle & title */
+ printf("%s - %s\n", subtitle, title);
puts("--------------------------------------------------------------------------------");
}
@@ -460,193 +457,59 @@ static void show_help (const struct Game_Iface_Out *board) static void show_help_start (void)
{
- puts("Move:");
- /* hjkl */
- printf(" %c", 'h');
- printf(" %c", 'j');
- printf(" %c", 'k');
- printf(" %c", 'l');
- putchar('\n');
- /* Arrows */
- printf(" %c", '<');
- printf(" %c", 'v');
- printf(" %c", '^');
- printf(" %c", '>');
- putchar('\n');
-
- puts("Step:");
- printf(" %c\n", '+');
-
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Move " "|Step " "|Save " "|Quit " "|Confirm");
+ printf(" %c%c%c%c %c%c%c%c| %c ""| %c ""| %c ""| Enter\n",
+ 'h','j','k','l',
+ '<','v','^','>',
+ '+', 's', 'q');
}
static void show_help_play (void)
{
- puts("Move:");
- /* hjkl */
- printf(" %c", 'h');
- printf(" %c", 'j');
- printf(" %c", 'k');
- printf(" %c", 'l');
- putchar('\n');
- /* Arrows */
- printf(" %c", '<');
- printf(" %c", 'v');
- printf(" %c", '^');
- printf(" %c", '>');
- putchar('\n');
-
- puts("Step:");
- printf(" %c\n", '+');
-
- puts("Flag:");
- printf(" Space\n");
-
- puts("Possible:");
- printf(" %c\n", 'f');
-
- puts("rm flag:");
- printf(" Backspace\n");
-
- puts("Pause:");
- printf(" %c\n", 'p');
-
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Move " "|Step " "|Flag |? " "|Remove |Pause " "|Save " "|Quit " "|Confirm");
+ printf(" %c%c%c%c %c%c%c%c| %c ""| Space| %c""| BS | %c ""| %c ""| %c ""| Enter\n",
+ 'h','j','k','l',
+ '<','v','^','>',
+ '+', 'f', 'p', 's', 'q');
}
static void show_help_pause (void)
{
-
- puts("Continue:");
- printf(" %c\n", 'p');
-
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Continue " "|Save " "|Quit " "|Confirm");
+ printf(" %c ""| %c ""| %c ""| Enter",
+ 'p', 's', 'q');
}
static void show_help_xyzzy (void)
{
- puts("XYZZY:");
- printf(" %c", '1');
- printf(" %c", '2');
- putchar('\n');
-
- puts("XYZZY off:");
- printf(" %c\n", '0');
-
- puts("Move:");
- /* hjkl */
- printf(" %c", 'h');
- printf(" %c", 'j');
- printf(" %c", 'k');
- printf(" %c", 'l');
- putchar('\n');
- /* Arrows */
- printf(" %c", '<');
- printf(" %c", 'v');
- printf(" %c", '^');
- printf(" %c", '>');
- putchar('\n');
-
- puts("Step:");
- printf(" %c\n", '+');
-
- puts("Flag:");
- printf(" Space\n");
-
- puts("Possible:");
- printf(" %c\n", 'f');
-
- puts("rm flag:");
- printf(" Backspace\n");
-
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "XYZZY |Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm");
+ printf(" 0 1 2| %c%c%c%c %c%c%c%c| %c ""| Space| %c""| BS | %c ""| %c ""| Enter\n",
+ 'h','j','k','l',
+ '<','v','^','>',
+ '+', 'f', 's', 'q');
}
static void show_help_cheat (void)
{
- puts("Move:");
- /* hjkl */
- printf(" %c", 'h');
- printf(" %c", 'j');
- printf(" %c", 'k');
- printf(" %c", 'l');
- putchar('\n');
- /* Arrows */
- printf(" %c", '<');
- printf(" %c", 'v');
- printf(" %c", '^');
- printf(" %c", '>');
- putchar('\n');
-
- puts("Step:");
- printf(" %c\n", '+');
-
- puts("Flag:");
- printf(" Space\n");
-
- puts("Possible:");
- printf(" %c\n", 'f');
-
- puts("rm flag:");
- printf(" Backspace\n");
-
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm");
+ printf(" %c%c%c%c %c%c%c%c| %c ""| Space| %c""| BS | %c ""| %c ""| Enter\n",
+ 'h','j','k','l',
+ '<','v','^','>',
+ '+', 'f', 's', 'q');
}
static void show_help_safe (void)
{
- puts("Save:");
- printf(" %c\n", 's');
-
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Save " "|Quit " "|Confirm");
+ printf(" %c ""| %c ""| Enter\n",
+ 's', 'q');
}
static void show_help_gameover (void)
{
- puts("Quit:");
- printf(" %c\n", 'q');
-
- puts("Confirm:");
- printf(" Enter\n");
+ puts( "Quit " "|Confirm");
+ printf(" %c ""| Enter\n",
+ 'q');
}
diff --git a/modules/player/src/player_iface.c b/modules/player/src/player_iface.c index 14009c9..83edc99 100644 --- a/modules/player/src/player_iface.c +++ b/modules/player/src/player_iface.c @@ -9,7 +9,7 @@ /* * * * * * * * * *
* * * Standard * * * * * *
* * * * * * * * * */
- /* sprintf() */
+ /* sprintf() & fflush() */
#include <stdio.h>
/* * * * * * * * * *
@@ -87,7 +87,7 @@ void player_iface_init (int rows, int cols) }
}
-void player_iface_start (int *pos_row, int *pos_col)
+int player_iface_start (int *pos_row, int *pos_col)
{
/* Title */
char title[TITLE_SIZE];
@@ -117,10 +117,23 @@ void player_iface_start (int *pos_row, int *pos_col) }
player_iface_act_start(player_action);
- } while (player_action != PLAYER_IFACE_ACT_STEP);
+ } while (player_action != PLAYER_IFACE_ACT_STEP &&
+ player_action != PLAYER_IFACE_ACT_QUIT);
*pos_row = player_iface_position.row;
*pos_col = player_iface_position.col;
+
+ int fail;
+ switch (player_action) {
+ case PLAYER_IFACE_ACT_STEP:
+ fail = 0;
+ break;
+
+ case PLAYER_IFACE_ACT_QUIT:
+ fail = -1;
+ break;
+ }
+ return fail;
}
void player_iface (const struct Game_Iface_Out *game_iface_out,
@@ -217,6 +230,7 @@ void player_iface_cleanup (void) player_tui_cleanup();
break;
}
+ fflush(stdout);
}
@@ -274,6 +288,7 @@ static void player_iface_act_start (int player_action) {
switch (player_action) {
case PLAYER_IFACE_ACT_STEP:
+ case PLAYER_IFACE_ACT_QUIT:
break;
case PLAYER_IFACE_ACT_MOVE_UP:
|