summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 04:19:20 +0100
committerAlejandroColomar <colomar.6.4.3@gmail.com>2019-01-07 04:19:20 +0100
commit4263106c125fba1791b5f78184812fdc11a0d394 (patch)
treed83ddbcb5df0b1d05598397e9168c662918f4c33
parent629b6ea7a8fd3dce3695f590b19a9475211ac6d6 (diff)
Fix style
-rw-r--r--modules/about/src/about.c14
-rw-r--r--modules/game/inc/game.h19
-rw-r--r--modules/game/inc/game_iface.h6
-rw-r--r--modules/game/src/game.c41
-rw-r--r--modules/game/src/game_iface.c68
-rw-r--r--modules/menu/src/parser.c32
-rw-r--r--modules/player/inc/player_clui.h18
-rw-r--r--modules/player/inc/player_gui.h8
-rw-r--r--modules/player/src/player_clui.c270
-rw-r--r--modules/player/src/player_gui.c261
-rw-r--r--modules/player/src/player_tui.c320
11 files changed, 502 insertions, 555 deletions
diff --git a/modules/about/src/about.c b/modules/about/src/about.c
index 1f829ad..c46f66b 100644
--- a/modules/about/src/about.c
+++ b/modules/about/src/about.c
@@ -9,6 +9,7 @@
/* Standard C ----------------------------------------------------------------*/
/* printf() */
#include <stdio.h>
+ #include <stdlib.h>
/* libalx ------------------------------------------------------------------*/
/* alx_prn_file() */
@@ -43,7 +44,18 @@ char share_path [FILENAME_MAX];
******************************************************************************/
void about_init (void)
{
- snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR);
+ if (snprintf(share_path, FILENAME_MAX, "%s/%s/",
+ INSTALL_SHARE_DIR,
+ SHARE_DIR) >= FILENAME_MAX) {
+ goto err_path;
+ }
+
+ return;
+
+
+err_path:
+ printf("Path is too large and has been truncated\n");
+ exit(EXIT_FAILURE);
}
void snprint_share_file (char *dest, int destsize, int share_file)
diff --git a/modules/game/inc/game.h b/modules/game/inc/game.h
index 74ec25c..6f95868 100644
--- a/modules/game/inc/game.h
+++ b/modules/game/inc/game.h
@@ -13,14 +13,10 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <stdbool.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* ยก Need to include these in the Makefile ! */
/* ROWS_MAX & COLS_MAX */
#include "game_iface.h"
@@ -76,17 +72,16 @@
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
- extern struct Game_Board game_board;
+extern struct Game_Board game_board;
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void game_init (void);
- void game_init_rand (int rows, int cols, int p,
- int pos_row, int pos_col);
- void game_init_load (int *rows, int *cols);
- void game_action (int action, int row, int col);
+void game_init (void);
+void game_init_rand (int rows, int cols, int mines, int pos_row, int pos_col);
+void game_init_load (int *rows, int *cols);
+void game_action (int action, int row, int col);
/******************************************************************************
diff --git a/modules/game/inc/game_iface.h b/modules/game/inc/game_iface.h
index b3f4ae5..51f0e8c 100644
--- a/modules/game/inc/game_iface.h
+++ b/modules/game/inc/game_iface.h
@@ -137,9 +137,9 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void game_iface_init_rand (int level, int pos_row, int pos_col);
- void game_iface_init_load (void);
- void game_iface (void);
+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.c b/modules/game/src/game.c
index 077d21c..9923e2f 100644
--- a/modules/game/src/game.c
+++ b/modules/game/src/game.c
@@ -6,9 +6,7 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
/* bool */
#include <stdbool.h>
/* rand() */
@@ -18,12 +16,11 @@
/* getpid() */
#include <unistd.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
/* seedf() */
#include "alx_seed.h"
+/* Project -------------------------------------------------------------------*/
#include "save.h"
#include "game.h"
@@ -32,7 +29,9 @@
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
-struct Game_Board game_board;
+/* Global --------------------------------------------------------------------*/
+ struct Game_Board game_board;
+/* Static --------------------------------------------------------------------*/
/******************************************************************************
@@ -59,17 +58,16 @@ static void game_flag_recursive (int r, int c);
/******************************************************************************
- ******* main *****************************************************************
+ ******* global functions *****************************************************
******************************************************************************/
-void game_init (void)
+void game_init (void)
{
int seed;
seed = seedf(clock(), time(NULL), getpid());
srand(seed);
}
-void game_init_rand (int rows, int cols, int mines,
- int pos_row, int pos_col)
+void game_init_rand (int rows, int cols, int mines, int pos_row, int pos_col)
{
/* size & mines */
game_board.rows = rows;
@@ -86,18 +84,18 @@ void game_init_rand (int rows, int cols, int mines,
game_init_adjnums();
}
-void game_init_load (int *rows, int *cols)
+void game_init_load (int *rows, int *cols)
{
- load_game_file();
+ load_game_file();
game_board.state = GAME_STATE_PLAYING;
-
*rows = game_board.rows;
*cols = game_board.cols;
}
-void game_action (int action, int row, int col)
+void game_action (int action, int row, int col)
{
+
switch (action) {
case GAME_ACT_STEP:
game_step(row, col);
@@ -128,6 +126,7 @@ static void game_init_clr (void)
{
int i;
int j;
+
for (i = 0; i < game_board.rows; i++) {
for (j = 0; j < game_board.cols; j++) {
game_board.gnd[i][j] = GAME_MINE_NO;
@@ -145,6 +144,7 @@ static void game_init_mines (int pos_row, int pos_col)
int i;
int r;
int c;
+
i = 0;
while (i < game_board.mines) {
r = (rand() % game_board.rows);
@@ -166,6 +166,7 @@ static void game_init_adjnums (void)
int c;
int i;
int j;
+
for (r = 0; r < game_board.rows; r++) {
for (c = 0; c < game_board.cols; c++) {
if (game_board.gnd[r][c] >= GAME_MINE_YES) {
@@ -188,6 +189,7 @@ static void game_init_adjnums (void)
* * * * * * * * * */
static void game_step (int r, int c)
{
+
switch (game_board.usr[r][c]) {
case GAME_USR_HIDDEN:
case GAME_USR_POSSIBLE:
@@ -203,8 +205,8 @@ static void game_step (int r, int c)
static void game_discover (int r, int c)
{
int safe_fields;
- safe_fields = (game_board.rows * game_board.cols) - game_board.mines;
+ safe_fields = (game_board.rows * game_board.cols) - game_board.mines;
if (game_board.gnd[r][c] >= GAME_MINE_YES) {
game_board.usr[r][c] = GAME_USR_KBOOM;
game_board.state = GAME_STATE_GAMEOVER;
@@ -240,8 +242,8 @@ static void game_discover_recursive (int r, int c)
static void game_big_step (int r, int c)
{
int cnt;
- cnt = game_count_flags(r, c);
+ cnt = game_count_flags(r, c);
if (cnt && (game_board.gnd[r][c] == cnt)) {
game_step_recursive(r, c);
}
@@ -293,6 +295,7 @@ static void game_step_recursive (int r, int c)
* * * * * * * * * */
static void game_flag (int r, int c)
{
+
switch (game_board.usr[r][c]) {
case GAME_USR_HIDDEN:
game_board.usr[r][c] = GAME_USR_FLAG;
@@ -316,6 +319,7 @@ static void game_flag (int r, int c)
static void game_possible (int r, int c)
{
+
switch (game_board.usr[r][c]) {
case GAME_USR_HIDDEN:
game_board.usr[r][c] = GAME_USR_POSSIBLE;
@@ -329,6 +333,7 @@ static void game_possible (int r, int c)
static void game_rmflag (int r, int c)
{
+
switch (game_board.usr[r][c]) {
case GAME_USR_FLAG:
game_board.usr[r][c] = GAME_USR_HIDDEN;
@@ -344,8 +349,8 @@ static void game_rmflag (int r, int c)
static void game_all_flags (int r, int c)
{
int cnt;
- cnt = game_count_nclear(r, c);
+ cnt = game_count_nclear(r, c);
if (cnt && (game_board.gnd[r][c] == cnt)) {
game_flag_recursive(r, c);
}
diff --git a/modules/game/src/game_iface.c b/modules/game/src/game_iface.c
index d4cc602..f5ae3e7 100644
--- a/modules/game/src/game_iface.c
+++ b/modules/game/src/game_iface.c
@@ -6,16 +6,12 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <stdbool.h>
/* time_t & time() */
#include <time.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* player_iface() */
#include "player_iface.h"
/* save_game_file() */
@@ -34,6 +30,8 @@
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
static struct Game_Iface_Out game_iface_out;
static struct Game_Iface_In game_iface_in;
static struct Game_Iface_Score game_iface_score;
@@ -75,10 +73,11 @@ static void game_iface_clean_in (void);
/******************************************************************************
- ******* main *****************************************************************
+ ******* global functions *****************************************************
******************************************************************************/
void game_iface_init_rand (int level, int pos_row, int pos_col)
{
+
/* first step */
game_action(GAME_ACT_STEP, pos_row, pos_col);
@@ -95,6 +94,7 @@ void game_iface_init_rand (int level, int pos_row, int pos_col)
void game_iface_init_load (void)
{
+
game_iface_init_cheated();
game_iface_out.rows = game_board.rows;
@@ -106,6 +106,7 @@ void game_iface_init_load (void)
void game_iface (void)
{
+
while (game_iface_out.state != GAME_IFACE_STATE_QUIT) {
game_iface_update_out();
game_iface_update_score();
@@ -126,6 +127,7 @@ void game_iface (void)
* * * * * * * * * */
static void game_iface_init_score (int level)
{
+
game_iface_score.level = level;
tim_ini = time(NULL);
game_iface_score.clicks = 1;
@@ -133,6 +135,7 @@ static void game_iface_init_score (int level)
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;
@@ -144,6 +147,7 @@ static void game_iface_init_cheated (void)
* * * * * * * * * */
static void game_iface_act (void)
{
+
switch (game_iface_out.state) {
case GAME_IFACE_STATE_PLAYING:
game_iface_playing_act();
@@ -173,6 +177,7 @@ static void game_iface_act (void)
static void game_iface_playing_act (void)
{
+
switch (game_iface_in.action) {
case GAME_IFACE_ACT_PLAY:
game_iface_act_game();
@@ -198,9 +203,10 @@ static void game_iface_playing_act (void)
static void game_iface_xyzzy_act (void)
{
+ bool wh;
+
xyzzy_init();
- bool wh;
wh = true;
while (wh) {
switch (game_iface_in.action) {
@@ -208,33 +214,27 @@ static void game_iface_xyzzy_act (void)
game_iface_act_game();
wh = false;
break;
-
case GAME_IFACE_ACT_XYZZY_OFF:
game_iface_xyzzy_off();
wh = false;
break;
-
case GAME_IFACE_ACT_XYZZY_LIN:
wh = xyzzy_lin(&game_iface_out, &game_iface_in);
game_iface_act_game();
break;
-
case GAME_IFACE_ACT_XYZZY_P:
wh = xyzzy_p(&game_iface_out, &game_iface_in);
game_iface_act_game();
game_iface_update_out();
break;
-
case GAME_IFACE_ACT_SAVE:
save_game_file(saved_path);
wh = false;
break;
-
case GAME_IFACE_ACT_QUIT:
game_iface_quit();
wh = false;
break;
-
default:
wh = false;
break;
@@ -244,19 +244,17 @@ static void game_iface_xyzzy_act (void)
static void game_iface_cheated_act (void)
{
+
switch (game_iface_in.action) {
case GAME_IFACE_ACT_PLAY:
game_iface_act_game();
break;
-
case GAME_IFACE_ACT_XYZZY_ON:
game_iface_xyzzy_on();
break;
-
case GAME_IFACE_ACT_SAVE:
save_game_file(saved_path);
break;
-
case GAME_IFACE_ACT_QUIT:
game_iface_quit();
break;
@@ -265,19 +263,17 @@ static void game_iface_cheated_act (void)
static void game_iface_pause_act (void)
{
+
switch (game_iface_in.action) {
case GAME_IFACE_ACT_PAUSE:
game_iface_unpause();
break;
-
case GAME_IFACE_ACT_XYZZY_ON:
game_iface_xyzzy_on();
break;
-
case GAME_IFACE_ACT_SAVE:
save_game_file(saved_path);
break;
-
case GAME_IFACE_ACT_QUIT:
game_iface_quit();
break;
@@ -286,12 +282,12 @@ static void game_iface_pause_act (void)
static void game_iface_safe_act (void)
{
+
switch (game_iface_in.action) {
case GAME_IFACE_ACT_SAVE:
game_iface_save_score();
game_iface_quit();
break;
-
case GAME_IFACE_ACT_QUIT:
game_iface_quit();
break;
@@ -300,6 +296,7 @@ static void game_iface_safe_act (void)
static void game_iface_gameover_act (void)
{
+
switch (game_iface_in.action) {
case GAME_IFACE_ACT_QUIT:
game_iface_quit();
@@ -348,33 +345,33 @@ static void game_iface_unpause (void)
static void game_iface_xyzzy_on (void)
{
+
game_iface_out.state = GAME_IFACE_STATE_XYZZY;
}
static void game_iface_xyzzy_off (void)
{
+
game_iface_out.state = GAME_IFACE_STATE_CHEATED;
}
static void game_iface_save_score (void)
{
+
/* Save board and score */
switch (game_iface_score.level) {
case GAME_IFACE_LEVEL_BEGINNER:
save_game_file(var_boards_beginner_path);
save_score(&game_iface_score);
break;
-
case GAME_IFACE_LEVEL_INTERMEDIATE:
save_game_file(var_boards_intermediate_path);
save_score(&game_iface_score);
break;
-
case GAME_IFACE_LEVEL_EXPERT:
save_game_file(var_boards_expert_path);
save_score(&game_iface_score);
break;
-
case GAME_IFACE_LEVEL_CUSTOM:
save_game_file(var_boards_custom_path);
break;
@@ -383,6 +380,7 @@ static void game_iface_save_score (void)
static void game_iface_quit (void)
{
+
game_iface_out.state = GAME_IFACE_STATE_QUIT;
}
@@ -391,6 +389,7 @@ static void game_iface_quit (void)
* * * * * * * * * */
static void game_iface_update_out (void)
{
+
game_iface_out.flags = game_board.flags;
game_iface_out.clr = game_board.clr;
@@ -398,7 +397,6 @@ static void game_iface_update_out (void)
case GAME_STATE_SAFE:
game_iface_out.state = GAME_IFACE_STATE_SAFE;
break;
-
case GAME_STATE_GAMEOVER:
game_iface_out.state = GAME_IFACE_STATE_GAMEOVER;
break;
@@ -432,27 +430,22 @@ static void game_iface_update_vis (int r, int c)
case GAME_USR_HIDDEN:
field_vis = GAME_IFACE_VIS_HIDDEN_FIELD;
break;
-
case GAME_USR_CLEAR:
field_vis = GAME_IFACE_VIS_0 + game_board.gnd[r][c];
break;
-
case GAME_USR_FLAG:
field_vis = GAME_IFACE_VIS_FLAG;
break;
-
case GAME_USR_POSSIBLE:
field_vis = GAME_IFACE_VIS_POSSIBLE;
break;
}
break;
-
case GAME_IFACE_STATE_SAFE:
switch (game_board.usr[r][c]) {
case GAME_USR_HIDDEN:
field_vis = GAME_IFACE_VIS_SAFE_MINE;
break;
-
case GAME_USR_CLEAR:
field_vis = GAME_IFACE_VIS_0 + game_board.gnd[r][c];
break;
@@ -460,19 +453,16 @@ static void game_iface_update_vis (int r, int c)
case GAME_USR_FLAG:
field_vis = GAME_IFACE_VIS_FLAG;
break;
-
case GAME_USR_POSSIBLE:
field_vis = GAME_IFACE_VIS_POSSIBLE;
break;
}
break;
-
case GAME_IFACE_STATE_GAMEOVER:
switch (game_board.usr[r][c]) {
case GAME_USR_KBOOM:
field_vis = GAME_IFACE_VIS_KBOOM;
break;
-
case GAME_USR_HIDDEN:
if (game_board.gnd[r][c] >= GAME_MINE_YES) {
field_vis = GAME_IFACE_VIS_HIDDEN_MINE;
@@ -480,11 +470,9 @@ static void game_iface_update_vis (int r, int c)
field_vis = GAME_IFACE_VIS_HIDDEN_SAFE;
}
break;
-
case GAME_USR_CLEAR:
field_vis = GAME_IFACE_VIS_0 + game_board.gnd[r][c];
break;
-
case GAME_USR_FLAG:
if (game_board.gnd[r][c] >= GAME_MINE_YES) {
field_vis = GAME_IFACE_VIS_FLAG;
@@ -492,7 +480,6 @@ static void game_iface_update_vis (int r, int c)
field_vis = GAME_IFACE_VIS_FLAG_FALSE;
}
break;
-
case GAME_USR_POSSIBLE:
if (game_board.gnd[r][c] >= GAME_MINE_YES) {
field_vis = GAME_IFACE_VIS_POSSIBLE;
@@ -502,7 +489,6 @@ static void game_iface_update_vis (int r, int c)
break;
}
break;
-
default:
field_vis = GAME_IFACE_VIS_HIDDEN_FIELD;
break;
@@ -519,23 +505,18 @@ static void game_iface_update_usr (int r, int c)
case GAME_USR_KBOOM:
field_usr = GAME_IFACE_USR_KBOOM;
break;
-
case GAME_USR_HIDDEN:
field_usr = GAME_IFACE_USR_HIDDEN;
break;
-
case GAME_USR_CLEAR:
field_usr = GAME_IFACE_USR_CLEAR;
break;
-
case GAME_USR_FLAG:
field_usr = GAME_IFACE_VIS_FLAG;
break;
-
case GAME_USR_POSSIBLE:
field_usr = GAME_IFACE_VIS_POSSIBLE;
break;
-
default:
field_usr = GAME_IFACE_VIS_FOO;
break;
@@ -556,7 +537,6 @@ static void game_iface_update_score (void)
tim_now = time(NULL);
game_iface_score.time = (int)(tim_now - tim_ini);
break;
-
case GAME_IFACE_STATE_XYZZY:
case GAME_IFACE_STATE_CHEATED:
game_iface_score.level = GAME_IFACE_LEVEL_CUSTOM;
@@ -573,12 +553,12 @@ static void game_iface_clean_in (void)
{
int i;
int j;
+
for (i = 0; i < game_board.rows; i++) {
for (j = 0; j < game_board.cols; j++) {
game_iface_in.act_game[i][j] = GAME_IFACE_GAME_ACT_FOO;
}
}
-
game_iface_in.action = GAME_IFACE_ACT_FOO;
}
diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c
index fed821d..37bc16f 100644
--- a/modules/menu/src/parser.c
+++ b/modules/menu/src/parser.c
@@ -6,20 +6,17 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <getopt.h>
/* FILE & fopen() & snprintf() & FILENAME_MAX */
#include <stdio.h>
/* exit() */
#include <stdlib.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
#include "alx_seed.h"
+/* Project -------------------------------------------------------------------*/
#include "about.h"
#include "game_iface.h"
#include "player_iface.h"
@@ -52,14 +49,14 @@ static void parse_start (char *argument);
/******************************************************************************
- ******* main *****************************************************************
+ ******* global functions *****************************************************
******************************************************************************/
void parser (int argc, char *argv[])
{
int opt = 0;
int opt_index = 0;
- struct option long_options[] = {
+ const struct option long_options[] = {
/* Standard */
{"exit", no_argument, 0, 'x'},
{"help", no_argument, 0, 'h'},
@@ -86,19 +83,15 @@ void parser (int argc, char *argv[])
case 'x':
flag_exit = true;
break;
-
case 'h':
print_share_file(SHARE_HELP);
exit(EXIT_SUCCESS);
-
case 'L':
print_share_file(SHARE_LICENSE);
exit(EXIT_SUCCESS);
-
case 'u':
print_share_file(SHARE_USAGE);
exit(EXIT_SUCCESS);
-
case 'v':
print_version();
exit(EXIT_SUCCESS);
@@ -107,19 +100,15 @@ void parser (int argc, char *argv[])
case 'a':
parse_rows(optarg);
break;
-
case 'b':
parse_columns(optarg);
break;
-
case 'f':
parse_file(optarg);
break;
-
case 'i':
parse_iface(optarg);
break;
-
case 'p':
parse_proportion(optarg);
break;
@@ -132,10 +121,8 @@ void parser (int argc, char *argv[])
case 's':
parse_start(optarg);
break;
-
case '?':
/* getopt_long already printed an error message. */
-
default:
print_share_file(SHARE_USAGE);
exit(EXIT_FAILURE);
@@ -149,6 +136,7 @@ void parser (int argc, char *argv[])
******************************************************************************/
static void parse_rows (char *argument)
{
+
menu_iface_variables.rows = atoi(argument);
if (menu_iface_variables.rows < 2 || menu_iface_variables.rows > ROWS_MAX) {
printf("--rows argument not valid\n");
@@ -159,6 +147,7 @@ static void parse_rows (char *argument)
static void parse_columns (char *argument)
{
+
menu_iface_variables.cols = atoi(argument);
if (menu_iface_variables.cols < 2 || menu_iface_variables.cols > COLS_MAX) {
printf("--columns argument not valid\n");
@@ -169,8 +158,9 @@ static void parse_columns (char *argument)
static void parse_file (char *argument)
{
- // FIXME
FILE *fp;
+
+ // FIXME
fp = fopen(argument, "r");
if (!fp) {
printf("--file argument not valid\n");
@@ -186,6 +176,7 @@ static void parse_file (char *argument)
static void parse_iface (char *argument)
{
+
menu_iface_mode = atoi(argument);
player_iface_mode = menu_iface_mode;
if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_GUI) {
@@ -197,6 +188,7 @@ static void parse_iface (char *argument)
static void parse_proportion (char *argument)
{
+
menu_iface_variables.p = atof(argument);
if (menu_iface_variables.p < 0 || menu_iface_variables.p > 1) {
printf("--proportion argument not valid\n");
@@ -208,12 +200,14 @@ static void parse_proportion (char *argument)
static void parse_rand_seed (char *argument)
{
int seed;
+
seed = atof(argument);
srand(seed);
}
#endif
static void parse_start (char *argument)
{
+
start_mode = atoi(argument);
if (start_mode < START_FOO || start_mode > START_LOAD) {
printf("--start argument not valid\n");
diff --git a/modules/player/inc/player_clui.h b/modules/player/inc/player_clui.h
index ffe7e25..a930918 100644
--- a/modules/player/inc/player_clui.h
+++ b/modules/player/inc/player_clui.h
@@ -48,18 +48,16 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void player_clui_start (const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle,
- int *action);
+void player_clui_start (const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle,
+ int *action);
-void player_clui (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle,
- int *action);
+void player_clui (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle,
+ int *action);
-void player_clui_save_name (const char *filepath, char *filename, int destsize);
+void player_clui_save_name (const char *fpath, char *fname, int destsize);
void player_clui_score_name (char *player_name, int destsize);
diff --git a/modules/player/inc/player_gui.h b/modules/player/inc/player_gui.h
index d9eb579..9cac01f 100644
--- a/modules/player/inc/player_gui.h
+++ b/modules/player/inc/player_gui.h
@@ -53,14 +53,14 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void player_gui_init (struct Player_Iface_Position *position,
+void player_gui_init (struct Player_Iface_Position *pos,
int *action);
-int player_gui_start (struct Player_Iface_Position *position,
+int player_gui_start (const struct Player_Iface_Position *pos,
const char *title, const char *subtitle);
-int player_gui (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position,
+int player_gui (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *pos,
const char *title, const char *subtitle);
void player_gui_save_name (const char *fpath, char *fname, int destsize);
diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c
index 06ca591..d08e676 100644
--- a/modules/player/src/player_clui.c
+++ b/modules/player/src/player_clui.c
@@ -6,17 +6,13 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <stdbool.h>
/* printf() & sscanf() */
#include <stdio.h>
#include <wchar.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* struct Game_Iface_Out */
#include "game_iface.h"
@@ -33,8 +29,20 @@
/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
******* variables ************************************************************
******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
static int oldaction;
@@ -42,26 +50,24 @@ static int oldaction;
******* static functions *****************************************************
******************************************************************************/
/* Start */
-static void show_board_start(const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle);
+static void show_board_start(const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle);
-static void board_loop_start(const struct Player_Iface_Position *position);
+static void board_loop_start(const struct Player_Iface_Position *position);
/* Play */
-static void show_board (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle);
+static void show_board (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle);
-static void board_loop (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position);
+static void board_loop (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position);
static char set_char (int game_iface_visible);
/* Input */
static int usr_input (void);
/* Help */
-static void show_help (const struct Game_Iface_Out *board);
+static void show_help (const struct Game_Iface_Out *board);
static void show_help_start (void);
static void show_help_play (void);
static void show_help_pause (void);
@@ -72,29 +78,24 @@ static void show_help_gameover (void);
/******************************************************************************
- ******* main *****************************************************************
+ ******* global functions *****************************************************
******************************************************************************/
-void player_clui_start (const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle,
- int *action)
+void player_clui_start (const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle,
+ int *action)
{
- /* User action */
+
show_help_start();
show_board_start(position, title, subtitle);
-
*action = usr_input();
oldaction = *action;
}
-void player_clui (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle,
- int *action)
+void player_clui (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle,
+ int *action)
{
- /* User action */
-
if (oldaction != PLAYER_IFACE_ACT_FOO) {
show_help(board);
@@ -104,15 +105,19 @@ void player_clui (const struct Game_Iface_Out *board,
oldaction = *action;
}
-void player_clui_save_name (const char *filepath, char *filename, int destsize)
+void player_clui_save_name (const char *fpath, char *fname, int destsize)
{
- puts("File name:");
- fgets(filename, destsize, stdin);
+
+ (void)fpath;
+
+ printf("File name:\n");
+ fgets(fname, destsize, stdin);
}
void player_clui_score_name (char *player_name, int destsize)
{
- puts("Your name:");
+
+ printf("Your name:\n");
fgets(player_name, destsize, stdin);
}
@@ -123,40 +128,37 @@ void player_clui_score_name (char *player_name, int destsize)
/* * * * * * * * * *
* * * Start * * * * * * *
* * * * * * * * * */
-static void show_board_start(const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle)
+static void show_board_start(const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle)
{
- /* Title */
- puts("________________________________________________________________________________");
- /* Board */
+ printf("________________________________________"
+ "________________________________________\n");
board_loop_start(position);
-
- /* Subtitle & title */
printf("%s - %s\n", subtitle, title);
- puts("--------------------------------------------------------------------------------");
+ printf("----------------------------------------"
+ "----------------------------------------\n");
}
-static void board_loop_start(const struct Player_Iface_Position *position)
+static void board_loop_start(const struct Player_Iface_Position *position)
{
int i;
int j;
- char ch;
+ char c;
putchar('\n');
for (i = 0; i < position->rows; i++) {
for (j = 0; j < position->cols; j++) {
- ch = PLAYER_CLUI_CHAR_HIDDEN_FIELD;
+ c = PLAYER_CLUI_CHAR_HIDDEN_FIELD;
/* Print char */
if (i == position->row && j == position->col) {
putchar('<');
- putchar(ch);
+ putchar(c);
putchar('>');
} else {
putchar(' ');
- putchar(ch);
+ putchar(c);
putchar(' ');
}
}
@@ -168,42 +170,40 @@ static void board_loop_start(const struct Player_Iface_Position *position)
/* * * * * * * * * *
* * * Play * * * * * *
* * * * * * * * * */
-static void show_board (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
- const char *title,
- const char *subtitle)
+static void show_board (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
+ const char *title, const char *subtitle)
{
- puts("________________________________________________________________________________");
- /* Board */
+ printf("________________________________________"
+ "________________________________________\n");
board_loop(board, position);
-
- /* Subtitle & title */
printf("%s - %s\n", subtitle, title);
- puts("--------------------------------------------------------------------------------");
+ printf("----------------------------------------"
+ "----------------------------------------\n");
}
-static void board_loop (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position)
+static void board_loop (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position)
{
int i;
int j;
- char ch;
+ char c;
putchar('\n');
for (i = 0; i < board->rows; i++) {
for (j = 0; j < board->cols; j++) {
- ch = set_char(board->visible[i][j]);
+ c = set_char(board->visible[i][j]);
/* Print char */
if (i == position->row && j == position->col) {
putchar('<');
- putchar(ch);
+ putchar(c);
putchar('>');
} else {
putchar(' ');
- putchar(ch);
+ putchar(c);
putchar(' ');
}
}
@@ -214,86 +214,87 @@ static void board_loop (const struct Game_Iface_Out *board,
static char set_char (int game_iface_visible)
{
- char ch;
+ char c;
+
switch (game_iface_visible) {
case GAME_IFACE_VIS_KBOOM:
- ch = PLAYER_CLUI_CHAR_KBOOM;
+ c = PLAYER_CLUI_CHAR_KBOOM;
break;
case GAME_IFACE_VIS_HIDDEN_FIELD:
- ch = PLAYER_CLUI_CHAR_HIDDEN_FIELD;
+ c = PLAYER_CLUI_CHAR_HIDDEN_FIELD;
break;
case GAME_IFACE_VIS_HIDDEN_MINE:
- ch = PLAYER_CLUI_CHAR_HIDDEN_MINE;
+ c = PLAYER_CLUI_CHAR_HIDDEN_MINE;
break;
case GAME_IFACE_VIS_HIDDEN_SAFE:
- ch = PLAYER_CLUI_CHAR_HIDDEN_SAFE;
+ c = PLAYER_CLUI_CHAR_HIDDEN_SAFE;
break;
case GAME_IFACE_VIS_SAFE_MINE:
- ch = PLAYER_CLUI_CHAR_SAFE_MINE;
+ c = PLAYER_CLUI_CHAR_SAFE_MINE;
break;
case GAME_IFACE_VIS_0:
- ch = PLAYER_CLUI_CHAR_0;
+ c = PLAYER_CLUI_CHAR_0;
break;
case GAME_IFACE_VIS_1:
- ch = PLAYER_CLUI_CHAR_1;
+ c = PLAYER_CLUI_CHAR_1;
break;
case GAME_IFACE_VIS_2:
- ch = PLAYER_CLUI_CHAR_2;
+ c = PLAYER_CLUI_CHAR_2;
break;
case GAME_IFACE_VIS_3:
- ch = PLAYER_CLUI_CHAR_3;
+ c = PLAYER_CLUI_CHAR_3;
break;
case GAME_IFACE_VIS_4:
- ch = PLAYER_CLUI_CHAR_4;
+ c = PLAYER_CLUI_CHAR_4;
break;
case GAME_IFACE_VIS_5:
- ch = PLAYER_CLUI_CHAR_5;
+ c = PLAYER_CLUI_CHAR_5;
break;
case GAME_IFACE_VIS_6:
- ch = PLAYER_CLUI_CHAR_6;
+ c = PLAYER_CLUI_CHAR_6;
break;
case GAME_IFACE_VIS_7:
- ch = PLAYER_CLUI_CHAR_7;
+ c = PLAYER_CLUI_CHAR_7;
break;
case GAME_IFACE_VIS_8:
- ch = PLAYER_CLUI_CHAR_8;
+ c = PLAYER_CLUI_CHAR_8;
break;
case GAME_IFACE_VIS_FLAG:
- ch = PLAYER_CLUI_CHAR_FLAG;
+ c = PLAYER_CLUI_CHAR_FLAG;
break;
case GAME_IFACE_VIS_FLAG_FALSE:
- ch = PLAYER_CLUI_CHAR_FLAG_FALSE;
+ c = PLAYER_CLUI_CHAR_FLAG_FALSE;
break;
case GAME_IFACE_VIS_POSSIBLE:
- ch = PLAYER_CLUI_CHAR_POSSIBLE;
+ c = PLAYER_CLUI_CHAR_POSSIBLE;
break;
case GAME_IFACE_VIS_POSSIBLE_FALSE:
- ch = PLAYER_CLUI_CHAR_POSSIBLE_FALSE;
+ c = PLAYER_CLUI_CHAR_POSSIBLE_FALSE;
break;
default:
- ch = PLAYER_CLUI_CHAR_ERROR;
+ c = PLAYER_CLUI_CHAR_ERROR;
break;
}
- return ch;
+ return c;
}
/* * * * * * * * * *
@@ -301,26 +302,41 @@ static char set_char (int game_iface_visible)
* * * * * * * * * */
static int usr_input (void)
{
- /* Wait for input */
char buff [BUFF_SIZE];
- char ch;
+ char c;
+ int action;
+ char *p;
+
+ action = PLAYER_IFACE_ACT_FOO;
+
+ /* Wait for input */
buff[0] = '\0';
- ch = '\0';
- fgets(buff, BUFF_SIZE, stdin);
+ c = '\0';
+ if (!fgets(buff, BUFF_SIZE, stdin)) {
+ goto err_fgets;
+ }
+ p = buff;
/* Interpret input */
- int action;
- action = PLAYER_IFACE_ACT_FOO;
- sscanf(buff, "%c", &ch);
- switch (ch) {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ switch (c) {
/* Escape sequence */
case 27:
/* Arrows */
- sscanf(buff, "%*c""%c", &ch);
- switch (ch) {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ switch (c) {
case 91:
- sscanf(buff, "%*2c""%c", &ch);
- switch (ch) {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ switch (c) {
case 65:
action = PLAYER_IFACE_ACT_MOVE_UP;
break;
@@ -385,17 +401,29 @@ static int usr_input (void)
case 'x':
/* Special sequence "xyzzy" */
- sscanf(buff, "%*c""%c", &ch);
- if (ch == 'y') {
- sscanf(buff, "%*2c""%c", &ch);
- if (ch == 'z') {
- sscanf(buff, "%*3c""%c", &ch);
- if (ch == 'z') {
- sscanf(buff, "%*4c""%c", &ch);
- if (ch == 'y') {
- action = PLAYER_IFACE_ACT_XYZZY_ON;
- }
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ if (c == 'y') {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
}
+ p++;
+ if (c == 'z') {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ if (c == 'z') {
+ if (sscanf(p, "%c", &c) != 1) {
+ goto err_sscanf;
+ }
+ p++;
+ if (c == 'y') {
+ action = PLAYER_IFACE_ACT_XYZZY_ON;
+ }
+ }
}
}
break;
@@ -421,14 +449,19 @@ static int usr_input (void)
break;
}
+
+err_sscanf:
+err_fgets:
+
return action;
}
/* * * * * * * * * *
* * * Help * * * * * * *
* * * * * * * * * */
-static void show_help (const struct Game_Iface_Out *board)
+static void show_help (const struct Game_Iface_Out *board)
{
+
switch (board->state) {
case GAME_IFACE_STATE_PLAYING:
show_help_play();
@@ -458,7 +491,8 @@ static void show_help (const struct Game_Iface_Out *board)
static void show_help_start (void)
{
- puts( "Move " "|Step " "|Quit " "|Confirm");
+
+ printf("Move " "|Step " "|Quit " "|Confirm\n");
printf(" %c%c%c%c %c%c%c%c| %c ""| %c ""| Enter\n",
'h','j','k','l',
'<','v','^','>',
@@ -467,7 +501,8 @@ static void show_help_start (void)
static void show_help_play (void)
{
- puts( "Move " "|Step " "|Flag |? " "|Remove |Pause " "|Save " "|Quit " "|Confirm");
+
+ printf("Move " "|Step " "|Flag |? " "|Remove |Pause " "|Save " "|Quit " "|Confirm\n");
printf(" %c%c%c%c %c%c%c%c| %c ""| Space| %c""| BS | %c ""| %c ""| %c ""| Enter\n",
'h','j','k','l',
'<','v','^','>',
@@ -476,14 +511,16 @@ static void show_help_play (void)
static void show_help_pause (void)
{
- puts( "Continue " "|Save " "|Quit " "|Confirm");
+
+ printf("Continue " "|Save " "|Quit " "|Confirm\n");
printf(" %c ""| %c ""| %c ""| Enter",
'p', 's', 'q');
}
static void show_help_xyzzy (void)
{
- puts( "XYZZY |Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm");
+
+ printf("XYZZY |Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm\n");
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','^','>',
@@ -492,7 +529,8 @@ static void show_help_xyzzy (void)
static void show_help_cheat (void)
{
- puts( "Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm");
+
+ printf("Move " "|Step " "|Flag |? " "|Remove |Save " "|Quit " "|Confirm\n");
printf(" %c%c%c%c %c%c%c%c| %c ""| Space| %c""| BS | %c ""| %c ""| Enter\n",
'h','j','k','l',
'<','v','^','>',
@@ -501,14 +539,16 @@ static void show_help_cheat (void)
static void show_help_safe (void)
{
- puts( "Save " "|Quit " "|Confirm");
+
+ printf("Save " "|Quit " "|Confirm\n");
printf(" %c ""| %c ""| Enter\n",
's', 'q');
}
static void show_help_gameover (void)
{
- puts( "Quit " "|Confirm");
+
+ printf("Quit " "|Confirm\n");
printf(" %c ""| Enter\n",
'q');
}
diff --git a/modules/player/src/player_gui.c b/modules/player/src/player_gui.c
index 40523da..f68e49c 100644
--- a/modules/player/src/player_gui.c
+++ b/modules/player/src/player_gui.c
@@ -153,26 +153,24 @@ static int state;
******* static functions *****************************************************
******************************************************************************/
/* Start */
-static void board_init (struct Player_Iface_Position *position,
+static void board_init (const struct Player_Iface_Position *pos,
int *action);
-static void show_board_start(struct Player_Iface_Position *position,
+static void show_board_start(const struct Player_Iface_Position *pos,
const char *title, const char *subtitle);
-static void board_loop_start(struct Player_Iface_Position *position);
+static void board_loop_start(const struct Player_Iface_Position *pos);
/* Play */
static void show_board (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position,
const char *title, const char *subtitle);
-static void board_loop (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position);
+static void board_loop (const struct Game_Iface_Out *board);
static char set_char (int game_iface_visible);
-static void show_char (struct Field_Data *field);
+static void show_char (const struct Field_Data *field);
/* Help */
static void help_init (int *action);
-static void show_help (const struct Game_Iface_Out *board);
+static void show_help (const struct Game_Iface_Out *board);
static void show_help_start (void);
static void show_help_play (void);
static void show_help_pause (void);
@@ -197,9 +195,12 @@ static gboolean callback_timeout (void *data);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void player_gui_init (struct Player_Iface_Position *position,
+void player_gui_init (struct Player_Iface_Position *pos,
int *action)
{
+ int i;
+ int j;
+
box = gtk_hbox_new(false, 0);
gtk_container_add(GTK_CONTAINER(window_gui), box);
@@ -213,17 +214,15 @@ void player_gui_init (struct Player_Iface_Position *position,
gtk_box_pack_start(GTK_BOX(box), box_board, true, true, 5);
help_init(action);
- board_init(position, action);
+ board_init(pos, action);
/* Board fields */
- int i;
- int j;
- for (i = 0; i < position->rows; i++) {
- for (j = 0; j < position->cols; j++) {
+ for (i = 0; i < pos->rows; i++) {
+ for (j = 0; j < pos->cols; j++) {
field[i][j].r = i;
field[i][j].c = j;
- field[i][j].row = &(position->row);
- field[i][j].col = &(position->col);
+ field[i][j].row = &(pos->row);
+ field[i][j].col = &(pos->col);
field[i][j].act = action;
field[i][j].ptr = gtk_button_new_with_label("NEW");
g_signal_connect(field[i][j].ptr, "button-press-event",
@@ -238,11 +237,12 @@ void player_gui_init (struct Player_Iface_Position *position,
gtk_widget_show_all(window_gui);
}
-int player_gui_start (struct Player_Iface_Position *position,
+int player_gui_start (const struct Player_Iface_Position *pos,
const char *title, const char *subtitle)
{
+
show_help_start();
- show_board_start(position, title, subtitle);
+ show_board_start(pos, title, subtitle);
/* Refresh */
gtk_widget_show(box);
@@ -253,14 +253,15 @@ int player_gui_start (struct Player_Iface_Position *position,
return 0;
}
-int player_gui (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position,
+int player_gui (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *pos,
const char *title, const char *subtitle)
{
+
state = board->state;
show_help(board);
- show_board(board, position, title, subtitle);
+ show_board(board, title, subtitle);
/* Refresh */
gtk_widget_show(box);
@@ -273,6 +274,7 @@ int player_gui (const struct Game_Iface_Out *board,
void player_gui_save_name (const char *fpath, char *fname, int destsize)
{
+
entry_fname.fpath = fpath;
entry_fname.fname = fname;
@@ -300,6 +302,7 @@ void player_gui_save_name (const char *fpath, char *fname, int destsize)
void player_gui_score_name (char *player_name, int destsize)
{
+
entry_name.str = player_name;
entry_name.strsize = destsize;
@@ -327,7 +330,7 @@ void player_gui_score_name (char *player_name, int destsize)
void player_gui_cleanup (void)
{
- /* Del box */
+
gtk_widget_destroy(box);
}
@@ -338,13 +341,13 @@ void player_gui_cleanup (void)
/* * * * * * * * * *
* * * Start * * * * * * *
* * * * * * * * * */
-static void board_init (struct Player_Iface_Position *position,
+static void board_init (const struct Player_Iface_Position *pos,
int *action)
{
- GtkWidget *separator[2];
+ GtkWidget *separator[2];
/* Box */
- box_board_in = gtk_vbox_new(false, 0);
+ box_board_in = gtk_vbox_new(false, 0);
gtk_box_pack_start(GTK_BOX(box_board), box_board_in, true, true, 5);
/* Title (with progress bar) */
@@ -359,46 +362,47 @@ static void board_init (struct Player_Iface_Position *position,
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pbar_board_tit.ptr), GTK_PROGRESS_LEFT_TO_RIGHT);
/* Separator */
- separator[0] = gtk_hseparator_new();
+ separator[0] = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(box_board_in), separator[0], false, false, 5);
/* Board */
- box_board_tab = gtk_vbox_new(true, 0);
+ box_board_tab = gtk_vbox_new(true, 0);
gtk_box_pack_start(GTK_BOX(box_board_in), box_board_tab, true, true, 0);
- table_board = gtk_table_new(position->rows, position->cols, true);
+ table_board = gtk_table_new(pos->rows, pos->cols, true);
gtk_box_pack_start(GTK_BOX(box_board_tab), table_board, true, true, 5);
/* Separator */
- separator[1] = gtk_hseparator_new();
+ separator[1] = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(box_board_in), separator[1], false, false, 5);
/* Subtitle (with cheats) */
- ebox_cheat.ptr = gtk_event_box_new();
-// box_board_stit = gtk_vbox_new(false, 0);
+ ebox_cheat.ptr = gtk_event_box_new();
+// box_board_stit = gtk_vbox_new(false, 0);
gtk_box_pack_start(GTK_BOX(box_board_in), ebox_cheat.ptr, false, false, 0);
// gtk_box_pack_start(GTK_BOX(box_board_in), box_board_stit, false, false, 0);
- label_stit.ptr = gtk_label_new("NEW");
+ label_stit.ptr = gtk_label_new("NEW");
gtk_container_add(GTK_CONTAINER(ebox_cheat.ptr), label_stit.ptr);
// gtk_box_pack_start(GTK_BOX(box_board_stit), label_stit.ptr, false, false, 0);
/* Cheats */
- ebox_cheat.val = PLAYER_IFACE_ACT_XYZZY_ON;
- ebox_cheat.act = action;
+ ebox_cheat.val = PLAYER_IFACE_ACT_XYZZY_ON;
+ ebox_cheat.act = action;
g_signal_connect(ebox_cheat.ptr, "button-press-event",
G_CALLBACK(callback_ebox), (void *)&ebox_cheat);
/* Timeout */
- timeout.val = PLAYER_IFACE_ACT_FOO;
- timeout.act = action;
- timeout.id = 0;
+ timeout.val = PLAYER_IFACE_ACT_FOO;
+ timeout.act = action;
+ timeout.id = 0;
/* Refresh */
gtk_widget_show_all(box_board);
}
-static void show_board_start(struct Player_Iface_Position *position,
+static void show_board_start(const struct Player_Iface_Position *pos,
const char *title, const char *subtitle)
{
+
/* Title */
snprintf(pbar_board_tit.text, LINE_SIZE, title);
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar_board_tit.ptr), pbar_board_tit.text);
@@ -408,7 +412,7 @@ static void show_board_start(struct Player_Iface_Position *position,
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar_board_tit.ptr), pbar_board_tit.frac);
/* Board */
- board_loop_start(position);
+ board_loop_start(pos);
/* Subtitle */
snprintf(label_stit.text, LINE_SIZE, subtitle);
@@ -418,17 +422,17 @@ static void show_board_start(struct Player_Iface_Position *position,
gtk_widget_show_all(box_board);
}
-static void board_loop_start(struct Player_Iface_Position *position)
+static void board_loop_start(const struct Player_Iface_Position *pos)
{
- int i;
- int j;
- char ch;
+ int i;
+ int j;
+ char c;
- ch = PLAYER_GUI_CHAR_HIDDEN_FIELD;
+ c = PLAYER_GUI_CHAR_HIDDEN_FIELD;
- for (i = 0; i < position->rows; i++) {
- for (j = 0; j < position->cols; j++) {
- field[i][j].ch = ch;
+ for (i = 0; i < pos->rows; i++) {
+ for (j = 0; j < pos->cols; j++) {
+ field[i][j].ch = c;
show_char(&field[i][j]);
}
}
@@ -437,8 +441,7 @@ static void board_loop_start(struct Player_Iface_Position *position)
/* * * * * * * * * *
* * * Play * * * * * *
* * * * * * * * * */
-static void show_board (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position,
+static void show_board (const struct Game_Iface_Out *board,
const char *title, const char *subtitle)
{
/* Title */
@@ -458,7 +461,7 @@ static void show_board (const struct Game_Iface_Out *board,
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar_board_tit.ptr), pbar_board_tit.frac);
/* Board */
- board_loop(board, position);
+ board_loop(board);
/* Subtitle */
snprintf(label_stit.text, LINE_SIZE, subtitle);
@@ -473,11 +476,10 @@ static void show_board (const struct Game_Iface_Out *board,
gtk_widget_show_all(box_board);
}
-static void board_loop (const struct Game_Iface_Out *board,
- struct Player_Iface_Position *position)
+static void board_loop (const struct Game_Iface_Out *board)
{
- int i;
- int j;
+ int i;
+ int j;
for (i = 0; i < board->rows; i++) {
for (j = 0; j < board->cols; j++) {
@@ -489,91 +491,75 @@ static void board_loop (const struct Game_Iface_Out *board,
static char set_char (int game_iface_visible)
{
- char ch;
+ char c;
+
switch (game_iface_visible) {
case GAME_IFACE_VIS_KBOOM:
- ch = PLAYER_GUI_CHAR_KBOOM;
+ c = PLAYER_GUI_CHAR_KBOOM;
break;
-
case GAME_IFACE_VIS_HIDDEN_FIELD:
- ch = PLAYER_GUI_CHAR_HIDDEN_FIELD;
+ c = PLAYER_GUI_CHAR_HIDDEN_FIELD;
break;
-
case GAME_IFACE_VIS_HIDDEN_MINE:
- ch = PLAYER_GUI_CHAR_HIDDEN_MINE;
+ c = PLAYER_GUI_CHAR_HIDDEN_MINE;
break;
-
case GAME_IFACE_VIS_HIDDEN_SAFE:
- ch = PLAYER_GUI_CHAR_HIDDEN_SAFE;
+ c = PLAYER_GUI_CHAR_HIDDEN_SAFE;
break;
-
case GAME_IFACE_VIS_SAFE_MINE:
- ch = PLAYER_GUI_CHAR_SAFE_MINE;
+ c = PLAYER_GUI_CHAR_SAFE_MINE;
break;
-
case GAME_IFACE_VIS_0:
- ch = PLAYER_GUI_CHAR_0;
+ c = PLAYER_GUI_CHAR_0;
break;
-
case GAME_IFACE_VIS_1:
- ch = PLAYER_GUI_CHAR_1;
+ c = PLAYER_GUI_CHAR_1;
break;
-
case GAME_IFACE_VIS_2:
- ch = PLAYER_GUI_CHAR_2;
+ c = PLAYER_GUI_CHAR_2;
break;
-
case GAME_IFACE_VIS_3:
- ch = PLAYER_GUI_CHAR_3;
+ c = PLAYER_GUI_CHAR_3;
break;
-
case GAME_IFACE_VIS_4:
- ch = PLAYER_GUI_CHAR_4;
+ c = PLAYER_GUI_CHAR_4;
break;
-
case GAME_IFACE_VIS_5:
- ch = PLAYER_GUI_CHAR_5;
+ c = PLAYER_GUI_CHAR_5;
break;
-
case GAME_IFACE_VIS_6:
- ch = PLAYER_GUI_CHAR_6;
+ c = PLAYER_GUI_CHAR_6;
break;
-
case GAME_IFACE_VIS_7:
- ch = PLAYER_GUI_CHAR_7;
+ c = PLAYER_GUI_CHAR_7;
break;
-
case GAME_IFACE_VIS_8:
- ch = PLAYER_GUI_CHAR_8;
+ c = PLAYER_GUI_CHAR_8;
break;
-
case GAME_IFACE_VIS_FLAG:
- ch = PLAYER_GUI_CHAR_FLAG;
+ c = PLAYER_GUI_CHAR_FLAG;
break;
-
case GAME_IFACE_VIS_FLAG_FALSE:
- ch = PLAYER_GUI_CHAR_FLAG_FALSE;
+ c = PLAYER_GUI_CHAR_FLAG_FALSE;
break;
-
case GAME_IFACE_VIS_POSSIBLE:
- ch = PLAYER_GUI_CHAR_POSSIBLE;
+ c = PLAYER_GUI_CHAR_POSSIBLE;
break;
-
case GAME_IFACE_VIS_POSSIBLE_FALSE:
- ch = PLAYER_GUI_CHAR_POSSIBLE_FALSE;
+ c = PLAYER_GUI_CHAR_POSSIBLE_FALSE;
break;
-
default:
- ch = PLAYER_GUI_CHAR_ERROR;
+ c = PLAYER_GUI_CHAR_ERROR;
break;
}
- return ch;
+ return c;
}
-static void show_char (struct Field_Data *field)
+static void show_char (const struct Field_Data *field)
{
char text [2];
+
sprintf(text, "%c", field->ch);
gtk_button_set_label(GTK_BUTTON(field->ptr), text);
}
@@ -583,6 +569,7 @@ static void show_char (struct Field_Data *field)
* * * * * * * * * */
static void help_init (int *action)
{
+
/* Box */
box_help_in = gtk_vbox_new(false, 0);
gtk_box_pack_start(GTK_BOX(box_help), box_help_in, false, false, 5);
@@ -600,34 +587,34 @@ static void help_init (int *action)
/* Data */
/* L click */
- button[BTN_CH_OFF].val = PLAYER_IFACE_ACT_XYZZY_OFF;
- button[BTN_CH_1].val = PLAYER_IFACE_ACT_XYZZY_LIN;
- button[BTN_CH_2].val = PLAYER_IFACE_ACT_XYZZY_P;
- tbutton[TBTN_PAUSE].val = PLAYER_IFACE_ACT_PAUSE;
- button[BTN_SAVE].val = PLAYER_IFACE_ACT_SAVE;
- button[BTN_QUIT].val = PLAYER_IFACE_ACT_QUIT;
+ button[BTN_CH_OFF].val = PLAYER_IFACE_ACT_XYZZY_OFF;
+ button[BTN_CH_1].val = PLAYER_IFACE_ACT_XYZZY_LIN;
+ button[BTN_CH_2].val = PLAYER_IFACE_ACT_XYZZY_P;
+ tbutton[TBTN_PAUSE].val = PLAYER_IFACE_ACT_PAUSE;
+ button[BTN_SAVE].val = PLAYER_IFACE_ACT_SAVE;
+ button[BTN_QUIT].val = PLAYER_IFACE_ACT_QUIT;
/* R click */
tbutton[TBTN_PAUSE].val2 = PLAYER_IFACE_ACT_PAUSE;
/* Action */
- button[BTN_CH_OFF].act = action;
- button[BTN_CH_1].act = action;
- button[BTN_CH_2].act = action;
- tbutton[TBTN_PAUSE].act = action;
- button[BTN_SAVE].act = action;
- button[BTN_QUIT].act = action;
+ button[BTN_CH_OFF].act = action;
+ button[BTN_CH_1].act = action;
+ button[BTN_CH_2].act = action;
+ tbutton[TBTN_PAUSE].act = action;
+ button[BTN_SAVE].act = action;
+ button[BTN_QUIT].act = action;
/* Generate widgets */
- button[BTN_CH_OFF].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_OFF].text);
- button[BTN_CH_1].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_1].text);
- button[BTN_CH_2].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_2].text);
- tbutton[TBTN_PAUSE].ptr = gtk_toggle_button_new_with_mnemonic(tbutton[TBTN_PAUSE].text);
- button[BTN_SAVE].ptr = gtk_button_new_with_mnemonic(button[BTN_SAVE].text);
- entry_fname.lbl.ptr = gtk_label_new(entry_fname.lbl.text);
- entry_fname.ptr = gtk_entry_new();
- entry_name.lbl.ptr = gtk_label_new(entry_name.lbl.text);
- entry_name.ptr = gtk_entry_new();
- button[BTN_QUIT].ptr = gtk_button_new_with_mnemonic(button[BTN_QUIT].text);
+ button[BTN_CH_OFF].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_OFF].text);
+ button[BTN_CH_1].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_1].text);
+ button[BTN_CH_2].ptr = gtk_button_new_with_mnemonic(button[BTN_CH_2].text);
+ tbutton[TBTN_PAUSE].ptr = gtk_toggle_button_new_with_mnemonic(tbutton[TBTN_PAUSE].text);
+ button[BTN_SAVE].ptr = gtk_button_new_with_mnemonic(button[BTN_SAVE].text);
+ entry_fname.lbl.ptr = gtk_label_new(entry_fname.lbl.text);
+ entry_fname.ptr = gtk_entry_new();
+ entry_name.lbl.ptr = gtk_label_new(entry_name.lbl.text);
+ entry_name.ptr = gtk_entry_new();
+ button[BTN_QUIT].ptr = gtk_button_new_with_mnemonic(button[BTN_QUIT].text);
/* Toggle buttons */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tbutton[TBTN_PAUSE].ptr), false);
@@ -665,6 +652,7 @@ static void help_init (int *action)
static void show_help (const struct Game_Iface_Out *board)
{
+
if (last_help != board->state) {
switch (board->state) {
case GAME_IFACE_STATE_PLAYING:
@@ -703,6 +691,7 @@ static void show_help (const struct Game_Iface_Out *board)
static void show_help_start (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -725,6 +714,7 @@ static void show_help_start (void)
static void show_help_play (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -740,6 +730,7 @@ static void show_help_play (void)
static void show_help_pause (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -755,6 +746,7 @@ static void show_help_pause (void)
static void show_help_xyzzy (void)
{
+
/* Show & hide */
gtk_widget_show(button[BTN_CH_OFF].ptr);
gtk_widget_show(button[BTN_CH_1].ptr);
@@ -770,6 +762,7 @@ static void show_help_xyzzy (void)
static void show_help_cheat (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -785,6 +778,7 @@ static void show_help_cheat (void)
static void show_help_safe (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -800,6 +794,7 @@ static void show_help_safe (void)
static void show_help_gameover (void)
{
+
/* Show & hide */
gtk_widget_hide(button[BTN_CH_OFF].ptr);
gtk_widget_hide(button[BTN_CH_1].ptr);
@@ -820,13 +815,13 @@ static gboolean callback_field (GtkWidget *widget,
GdkEventButton *event,
void *data)
{
+ struct Field_Data *field_ij;
+
if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
g_source_remove(timeout.id);
}
- struct Field_Data *field_ij;
field_ij = ((struct Field_Data *)data);
-
*(field_ij->row) = field_ij->r;
*(field_ij->col) = field_ij->c;
@@ -855,12 +850,13 @@ static gboolean callback_ebox (GtkWidget *widget,
GdkEventButton *event,
void *data)
{
- if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
+ struct EBox_Data *ebox;
+
+ if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) {
g_source_remove(timeout.id);
}
- struct EBox_Data *ebox;
- ebox = ((struct EBox_Data *)data);
+ ebox = ((struct EBox_Data *)data);
switch (event->button) {
case 1:
@@ -883,14 +879,14 @@ static gboolean callback_ebox (GtkWidget *widget,
static void callback_button (GtkWidget *widget, void *data)
{
- if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
+ struct Button_Data *button;
+
+ if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) {
g_source_remove(timeout.id);
}
- struct Button_Data *button;
- button = ((struct Button_Data *)data);
-
- *(button->act) = button->val;
+ button = ((struct Button_Data *)data);
+ *(button->act) = button->val;
gtk_main_quit();
@@ -898,12 +894,13 @@ static void callback_button (GtkWidget *widget, void *data)
static gboolean callback_tbutton (GtkWidget *widget, void *data)
{
- if (state == GAME_IFACE_STATE_PLAYING && timeout.id) {
+ struct TButton_Data *tbutton;
+
+ if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) {
g_source_remove(timeout.id);
}
- struct TButton_Data *tbutton;
- tbutton = ((struct TButton_Data *)data);
+ tbutton = ((struct TButton_Data *)data);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
/* If control reaches here, the toggle button is down */
@@ -928,7 +925,6 @@ static void callback_entry_fname (GtkWidget *widget, void *data)
char buff [LINE_SIZE];
entry = ((struct Entry_fname_Data *)data);
-
str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
err = alx_sscan_fname(entry->fpath, entry->fname, false, str);
@@ -948,7 +944,6 @@ static void callback_entry_str (GtkWidget *widget, void *data)
const char *str;
entry = ((struct Entry_str_Data *)data);
-
str = gtk_entry_get_text(GTK_ENTRY(entry->ptr));
snprintf(entry->str, entry->strsize, "%s", str);
@@ -958,9 +953,9 @@ static void callback_entry_str (GtkWidget *widget, void *data)
static gboolean callback_timeout (void *data)
{
struct Timeout_Data *tout;
- tout = ((struct Timeout_Data *)data);
- *(tout->act) = tout->val;
+ tout = ((struct Timeout_Data *)data);
+ *(tout->act) = tout->val;
gtk_main_quit();
diff --git a/modules/player/src/player_tui.c b/modules/player/src/player_tui.c
index b5209ed..899b054 100644
--- a/modules/player/src/player_tui.c
+++ b/modules/player/src/player_tui.c
@@ -47,28 +47,28 @@ static int last_help;
******* static functions *****************************************************
******************************************************************************/
/* Start */
-static void show_board_start(const struct Player_Iface_Position *position,
+static void show_board_start(const struct Player_Iface_Position *position,
const char *title, const char *subtitle);
-static void board_loop_start(const struct Player_Iface_Position *position);
+static void board_loop_start(const struct Player_Iface_Position *position);
/* Play */
-static void show_board (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
+static void show_board (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
const char *title, const char *subtitle);
-static void board_loop (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position);
+static void board_loop (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position);
-static void highlight_cursor(wchar_t wch,
- const struct Player_Iface_Position *position);
+static void highlight_cursor(wchar_t c,
+ const struct Player_Iface_Position *position);
-static wchar_t set_char (int game_iface_visible);
-static void show_char (int row, int col, wchar_t wch);
+static wchar_t set_char (int tile);
+static void show_char (int row, int col, wchar_t c);
/* Input */
static int usr_input (void);
/* Help */
-static void show_help (const struct Game_Iface_Out *board);
+static void show_help (const struct Game_Iface_Out *board);
static void show_help_start (void);
static void show_help_play (void);
static void show_help_pause (void);
@@ -83,10 +83,17 @@ static void show_help_gameover (void);
******************************************************************************/
void player_tui_init (int rows, int cols)
{
- /* Use curses mode */
+ int h1;
+ int w1;
+ int r1;
+ int c1;
+ int h2;
+ int w2;
+ int r2;
+ int c2;
+
alx_resume_curses();
- /* Colors */
flag_color = false;
if (has_colors()) {
flag_color = true;
@@ -118,17 +125,17 @@ void player_tui_init (int rows, int cols)
}
/* Dimensions: board */
- const int h1 = rows + 2;
- const int w1 = 2 * cols + 3;
- const int r1 = 0;
- const int c1 = 11;
+ h1 = rows + 2;
+ w1 = 2 * cols + 3;
+ r1 = 0;
+ c1 = 11;
win_board = newwin(h1, w1, r1, c1);
/* Dimensions: help */
- const int h2 = 24;
- const int w2 = 10;
- const int r2 = 0;
- const int c2 = 0;
+ h2 = 24;
+ w2 = 10;
+ r2 = 0;
+ c2 = 0;
win_help = newwin(h2, w2, r2, c2);
/* Activate keypad, don't echo input, and set timeout = REFRESH_TIME_MS ms */
@@ -137,7 +144,7 @@ void player_tui_init (int rows, int cols)
wtimeout(win_board, REFRESH_TIME_MS);
}
-int player_tui_start (const struct Player_Iface_Position *position,
+int player_tui_start (const struct Player_Iface_Position *position,
const char *title, const char *subtitle,
int *action)
{
@@ -149,8 +156,8 @@ int player_tui_start (const struct Player_Iface_Position *position,
return 0;
}
-int player_tui (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
+int player_tui (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
const char *title, const char *subtitle,
int *action)
{
@@ -167,10 +174,8 @@ void player_tui_save_name (const char *fpath, char *fname, int destsize)
int w;
int r;
- /* Input box */
w = 60;
r = 10;
- /* Request name */
alx_w_getfname(fpath, fname, false, w, r, "File name:", NULL);
}
@@ -179,10 +184,8 @@ void player_tui_score_name (char *player_name, int destsize)
int w;
int r;
- /* Input box */
w = 60;
r = 10;
- /* Request name */
alx_w_getstr(player_name, destsize, w, r, "Your name:", NULL);
}
@@ -201,37 +204,29 @@ void player_tui_cleanup (void)
/* * * * * * * * * *
* * * Start * * * * * * *
* * * * * * * * * */
-static void show_board_start(const struct Player_Iface_Position *position,
+static void show_board_start(const struct Player_Iface_Position *position,
const char *title, const char *subtitle)
{
- /* Clear & box */
werase(win_board);
box(win_board, 0, 0);
- /* Title */
alx_ncur_prn_title(win_board, title);
- /* Subtitle */
alx_ncur_prn_subtitle(win_board, subtitle);
-
- /* Board */
board_loop_start(position);
-
- /* Cursor */
wmove(win_board, 1 + position->row, 2 + 2 * position->col);
- /* Refresh */
wrefresh(win_board);
}
-static void board_loop_start(const struct Player_Iface_Position *position)
+static void board_loop_start(const struct Player_Iface_Position *position)
{
int i;
int j;
-
int k;
int l;
- wchar_t wch;
- wch = PLAYER_TUI_CHAR_HIDDEN_FIELD;
+ wchar_t c;
+
+ c = PLAYER_TUI_CHAR_HIDDEN_FIELD;
for (i = 0; i < position->rows; i++) {
k = 1 + i;
@@ -240,21 +235,21 @@ static void board_loop_start(const struct Player_Iface_Position *position)
for (j = 0; j < position->cols; j++) {
l = 2 + 2 * j;
- show_char(k, l, wch);
+ show_char(k, l, c);
}
}
/* Highlight cursor */
if (position->highlight) {
- highlight_cursor(wch, position);
+ highlight_cursor(c, position);
}
}
/* * * * * * * * * *
* * * Play * * * * * *
* * * * * * * * * */
-static void show_board (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position,
+static void show_board (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position,
const char *title, const char *subtitle)
{
/* Clear & box */
@@ -276,14 +271,14 @@ static void show_board (const struct Game_Iface_Out *board,
wrefresh(win_board);
}
-static void board_loop (const struct Game_Iface_Out *board,
- const struct Player_Iface_Position *position)
+static void board_loop (const struct Game_Iface_Out *board,
+ const struct Player_Iface_Position *position)
{
int i;
int j;
int k;
int l;
- wchar_t wch;
+ wchar_t c;
for (i = 0; i < board->rows; i++) {
k = 1 + i;
@@ -292,8 +287,8 @@ static void board_loop (const struct Game_Iface_Out *board,
for (j = 0; j < board->cols; j++) {
l = 2 + 2 * j;
if (board->usr[i][j] == GAME_IFACE_USR_CLEAR) {
- wch = set_char(board->visible[i][j]);
- show_char(k, l, wch);
+ c = set_char(board->visible[i][j]);
+ show_char(k, l, c);
}
}
/* xyzzy */
@@ -301,29 +296,29 @@ static void board_loop (const struct Game_Iface_Out *board,
for (j = 0; j < board->cols; j++) {
l = 2 + 2 * j;
if (board->usr[i][j] != GAME_IFACE_USR_CLEAR) {
- wch = set_char(board->visible[i][j]);
- show_char(k, l, wch);
+ c = set_char(board->visible[i][j]);
+ show_char(k, l, c);
}
}
/* kboom */
for (j = 0; j < board->cols; j++) {
l = 2 + 2 * j;
if (board->usr[i][j] == GAME_IFACE_USR_KBOOM) {
- wch = set_char(board->visible[i][j]);
- show_char(k, l, wch);
+ c = set_char(board->visible[i][j]);
+ show_char(k, l, c);
}
}
}
/* Highlight cursor */
if (position->highlight) {
- wch = set_char(board->visible[position->row][position->col]);
- highlight_cursor(wch, position);
+ c = set_char(board->visible[position->row][position->col]);
+ highlight_cursor(c, position);
}
}
-static void highlight_cursor(wchar_t wch,
- const struct Player_Iface_Position *position)
+static void highlight_cursor(wchar_t c,
+ const struct Player_Iface_Position *position)
{
int k;
int l;
@@ -337,179 +332,145 @@ static void highlight_cursor(wchar_t wch,
wattron(win_board, A_BOLD | COLOR_PAIR(pair));
}
mvwaddch(win_board, k, l - 1, '<');
- mvwaddch(win_board, k, l, wch);
+ mvwaddch(win_board, k, l, c);
mvwaddch(win_board, k, l + 1, '>');
if (flag_color) {
wattroff(win_board, A_BOLD | COLOR_PAIR(pair));
}
}
-static wchar_t set_char (int game_iface_visible)
+static wchar_t set_char (int tile)
{
- wchar_t wch;
- switch (game_iface_visible) {
+ wchar_t c;
+
+ switch (tile) {
case GAME_IFACE_VIS_KBOOM:
- wch = PLAYER_TUI_CHAR_KBOOM;
+ c = PLAYER_TUI_CHAR_KBOOM;
break;
-
case GAME_IFACE_VIS_HIDDEN_FIELD:
- wch = PLAYER_TUI_CHAR_HIDDEN_FIELD;
+ c = PLAYER_TUI_CHAR_HIDDEN_FIELD;
break;
-
case GAME_IFACE_VIS_HIDDEN_MINE:
- wch = PLAYER_TUI_CHAR_HIDDEN_MINE;
+ c = PLAYER_TUI_CHAR_HIDDEN_MINE;
break;
-
case GAME_IFACE_VIS_HIDDEN_SAFE:
- wch = PLAYER_TUI_CHAR_HIDDEN_SAFE;
+ c = PLAYER_TUI_CHAR_HIDDEN_SAFE;
break;
-
case GAME_IFACE_VIS_SAFE_MINE:
- wch = PLAYER_TUI_CHAR_SAFE_MINE;
+ c = PLAYER_TUI_CHAR_SAFE_MINE;
break;
-
case GAME_IFACE_VIS_0:
- wch = PLAYER_TUI_CHAR_0;
+ c = PLAYER_TUI_CHAR_0;
break;
-
case GAME_IFACE_VIS_1:
- wch = PLAYER_TUI_CHAR_1;
+ c = PLAYER_TUI_CHAR_1;
break;
-
case GAME_IFACE_VIS_2:
- wch = PLAYER_TUI_CHAR_2;
+ c = PLAYER_TUI_CHAR_2;
break;
-
case GAME_IFACE_VIS_3:
- wch = PLAYER_TUI_CHAR_3;
+ c = PLAYER_TUI_CHAR_3;
break;
-
case GAME_IFACE_VIS_4:
- wch = PLAYER_TUI_CHAR_4;
+ c = PLAYER_TUI_CHAR_4;
break;
-
case GAME_IFACE_VIS_5:
- wch = PLAYER_TUI_CHAR_5;
+ c = PLAYER_TUI_CHAR_5;
break;
-
case GAME_IFACE_VIS_6:
- wch = PLAYER_TUI_CHAR_6;
+ c = PLAYER_TUI_CHAR_6;
break;
-
case GAME_IFACE_VIS_7:
- wch = PLAYER_TUI_CHAR_7;
+ c = PLAYER_TUI_CHAR_7;
break;
-
case GAME_IFACE_VIS_8:
- wch = PLAYER_TUI_CHAR_8;
+ c = PLAYER_TUI_CHAR_8;
break;
-
case GAME_IFACE_VIS_FLAG:
- wch = PLAYER_TUI_CHAR_FLAG;
+ c = PLAYER_TUI_CHAR_FLAG;
break;
-
case GAME_IFACE_VIS_FLAG_FALSE:
- wch = PLAYER_TUI_CHAR_FLAG_FALSE;
+ c = PLAYER_TUI_CHAR_FLAG_FALSE;
break;
-
case GAME_IFACE_VIS_POSSIBLE:
- wch = PLAYER_TUI_CHAR_POSSIBLE;
+ c = PLAYER_TUI_CHAR_POSSIBLE;
break;
-
case GAME_IFACE_VIS_POSSIBLE_FALSE:
- wch = PLAYER_TUI_CHAR_POSSIBLE_FALSE;
+ c = PLAYER_TUI_CHAR_POSSIBLE_FALSE;
break;
-
default:
- wch = PLAYER_TUI_CHAR_ERROR;
+ c = PLAYER_TUI_CHAR_ERROR;
break;
}
- return wch;
+ return c;
}
-static void show_char (int row, int col, wchar_t wch)
+static void show_char (int row, int col, wchar_t c)
{
- /* Select attributes */
int pair;
- switch (wch) {
+
+ switch (c) {
case PLAYER_TUI_CHAR_1:
- pair = PAIR_1;
+ pair = PAIR_1;
break;
-
case PLAYER_TUI_CHAR_2:
- pair = PAIR_2;
+ pair = PAIR_2;
break;
-
case PLAYER_TUI_CHAR_3:
- pair = PAIR_3;
+ pair = PAIR_3;
break;
-
case PLAYER_TUI_CHAR_4:
- pair = PAIR_4;
+ pair = PAIR_4;
break;
-
case PLAYER_TUI_CHAR_5:
- pair = PAIR_5;
+ pair = PAIR_5;
break;
-
case PLAYER_TUI_CHAR_6:
- pair = PAIR_6;
+ pair = PAIR_6;
break;
-
case PLAYER_TUI_CHAR_7:
- pair = PAIR_7;
+ pair = PAIR_7;
break;
-
case PLAYER_TUI_CHAR_8:
- pair = PAIR_8;
+ pair = PAIR_8;
break;
-
case PLAYER_TUI_CHAR_0:
- pair = PAIR_BLANK;
+ pair = PAIR_BLANK;
break;
-
case PLAYER_TUI_CHAR_HIDDEN_MINE:
case PLAYER_TUI_CHAR_SAFE_MINE:
- pair = PAIR_MINE;
+ pair = PAIR_MINE;
break;
-
case PLAYER_TUI_CHAR_HIDDEN_FIELD:
case PLAYER_TUI_CHAR_HIDDEN_SAFE:
- pair = PAIR_HIDDEN;
+ pair = PAIR_HIDDEN;
break;
-
case PLAYER_TUI_CHAR_POSSIBLE_FALSE:
- pair = PAIR_fail;
+ pair = PAIR_fail;
break;
-
case PLAYER_TUI_CHAR_POSSIBLE:
- pair = PAIR_POSSIBLE;
+ pair = PAIR_POSSIBLE;
break;
-
case PLAYER_TUI_CHAR_FLAG_FALSE:
- pair = PAIR_FAIL;
+ pair = PAIR_FAIL;
break;
-
case PLAYER_TUI_CHAR_FLAG:
- pair = PAIR_FLAG;
+ pair = PAIR_FLAG;
break;
-
case PLAYER_TUI_CHAR_KBOOM:
- pair = PAIR_KBOOM;
+ pair = PAIR_KBOOM;
break;
-
default:
- pair = PAIR_KBOOM;
+ pair = PAIR_KBOOM;
break;
}
- /* Print char */
if (flag_color) {
wattron(win_board, A_BOLD | COLOR_PAIR(pair));
}
mvwaddch(win_board, row, col - 1, ' ');
- mvwaddch(win_board, row, col, wch);
+ mvwaddch(win_board, row, col, c);
mvwaddch(win_board, row, col + 1, ' ');
if (flag_color) {
wattroff(win_board, A_BOLD | COLOR_PAIR(pair));
@@ -522,21 +483,19 @@ static void show_char (int row, int col, wchar_t wch)
static int usr_input (void)
{
wchar_t ch;
- ch = wgetch(win_board);
-
int action;
+ ch = wgetch(win_board);
+
switch (ch) {
case '+':
case '\r':
case '\n':
action = PLAYER_IFACE_ACT_STEP;
break;
-
case ' ':
action = PLAYER_IFACE_ACT_FLAG;
break;
-
case 'f':
action = PLAYER_IFACE_ACT_FLAG_POSSIBLE;
break;
@@ -546,17 +505,13 @@ static int usr_input (void)
case 0x08:
action = PLAYER_IFACE_ACT_RM_FLAG;
break;
-
-
case KEY_BREAK:
case 'p':
action = PLAYER_IFACE_ACT_PAUSE;
break;
-
case 's':
action = PLAYER_IFACE_ACT_SAVE;
break;
-
case 'x':
/* Wait for special sequence "xyzzy" */
wtimeout(win_board, 1000);
@@ -565,67 +520,53 @@ static int usr_input (void)
if (ch == 'y') {
ch = wgetch(win_board);
if (ch == 'z') {
-
- ch = wgetch(win_board);
- if (ch == 'z') {
-
- ch = wgetch(win_board);
- if (ch == 'y') {
- action = PLAYER_IFACE_ACT_XYZZY_ON;
- }
- }
+ ch = wgetch(win_board);
+ if (ch == 'z') {
+ ch = wgetch(win_board);
+ if (ch == 'y') {
+ action = PLAYER_IFACE_ACT_XYZZY_ON;
+ }
+ }
}
}
/* Resume */
wtimeout(win_board, REFRESH_TIME_MS);
break;
-
case '0':
action = PLAYER_IFACE_ACT_XYZZY_OFF;
break;
-
case '1':
action = PLAYER_IFACE_ACT_XYZZY_LIN;
break;
-
case '2':
action = PLAYER_IFACE_ACT_XYZZY_P;
break;
-
case '3':
action = PLAYER_IFACE_ACT_XYZZY_NP;
break;
-
case 'q':
action = PLAYER_IFACE_ACT_QUIT;
break;
-
-
case KEY_LEFT:
case 'h':
action = PLAYER_IFACE_ACT_MOVE_LEFT;
break;
-
case KEY_DOWN:
case 'j':
action = PLAYER_IFACE_ACT_MOVE_DOWN;
break;
-
case KEY_UP:
case 'k':
action = PLAYER_IFACE_ACT_MOVE_UP;
break;
-
case KEY_RIGHT:
case 'l':
action = PLAYER_IFACE_ACT_MOVE_RIGHT;
break;
-
case 'c':
action = PLAYER_IFACE_ACT_HIGHLIGHT;
break;
-
default:
action = PLAYER_IFACE_ACT_FOO;
break;
@@ -640,53 +581,43 @@ static int usr_input (void)
static void show_help (const struct Game_Iface_Out *board)
{
if (last_help != board->state) {
- /* Clear */
werase(win_help);
switch (board->state) {
case GAME_IFACE_STATE_PLAYING:
show_help_play();
break;
-
case GAME_IFACE_STATE_PAUSE:
show_help_pause();
break;
-
case GAME_IFACE_STATE_XYZZY:
show_help_xyzzy();
break;
-
case GAME_IFACE_STATE_CHEATED:
show_help_cheat();
break;
-
case GAME_IFACE_STATE_SAFE:
show_help_safe();
break;
-
case GAME_IFACE_STATE_GAMEOVER:
show_help_gameover();
break;
}
- /* Refresh */
wrefresh(win_help);
-
- /* Update last_help */
last_help = board->state;
}
}
static void show_help_start (void)
{
- /* Clear */
- werase(win_help);
-
int r;
int c;
- r = 0;
- c = 0;
+ werase(win_help);
+
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c++, "Move:");
/* hjkl */
mvwaddch(win_help, r, c, 'h');
@@ -718,10 +649,7 @@ static void show_help_start (void)
mvwaddstr(win_help, r++, c, "Quit:");
mvwprintw(win_help, r++, c, " %c", 'q');
- /* Refresh */
wrefresh(win_help);
-
- /* Update last_help */
last_help = GAME_IFACE_STATE_FOO;
}
@@ -730,8 +658,8 @@ static void show_help_play (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c++, "Move:");
/* hjkl */
mvwaddch(win_help, r, c, 'h');
@@ -784,8 +712,8 @@ static void show_help_pause (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c, "Cursor:");
mvwprintw(win_help, r++, c, " %c", 'c');
@@ -804,8 +732,8 @@ static void show_help_xyzzy (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c++, "XYZZY:");
mvwprintw(win_help, r, c, "%c", '1');
c += 2;
@@ -867,8 +795,8 @@ static void show_help_cheat (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c++, "Move:");
/* hjkl */
mvwaddch(win_help, r, c, 'h');
@@ -918,8 +846,8 @@ static void show_help_safe (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c, "Save:");
mvwprintw(win_help, r++, c, " %c", 's');
@@ -932,8 +860,8 @@ static void show_help_gameover (void)
int r;
int c;
- r = 0;
- c = 0;
+ r = 0;
+ c = 0;
mvwaddstr(win_help, r++, c, "Quit:");
mvwprintw(win_help, r++, c, " %c", 'q');
}