From 3aede2897e53bd0f9a5d6da1da98873fc5e6b42b Mon Sep 17 00:00:00 2001 From: alejandro-colomar Date: Sun, 23 Jun 2019 03:48:17 +0200 Subject: New version: tui/clui only, linux only --- .gitignore | 0 .gitmodules | 0 COPYING.txt | 0 Makefile | 231 +++---- README.txt | 0 bin/Makefile | 66 +- inc/mine-sweeper/about/about.h | 65 ++ inc/mine-sweeper/ctrl/start.h | 43 ++ inc/mine-sweeper/game/core.h | 109 +++ inc/mine-sweeper/game/iface.h | 175 +++++ inc/mine-sweeper/menu/clui.h | 27 + inc/mine-sweeper/menu/iface.h | 67 ++ inc/mine-sweeper/menu/parser.h | 27 + inc/mine-sweeper/menu/tui.h | 27 + inc/mine-sweeper/player/clui.h | 73 ++ inc/mine-sweeper/player/iface.h | 112 ++++ inc/mine-sweeper/player/tui.h | 113 ++++ inc/mine-sweeper/save/save.h | 57 ++ inc/mine-sweeper/save/score.h | 62 ++ inc/mine-sweeper/xyzzy/xyzzy.h | 37 ++ libalx | 2 +- modules/Makefile | 67 -- modules/about/Makefile | 24 - modules/about/inc/about.h | 62 -- modules/about/src/about.c | 123 ---- modules/about/tmp/Makefile | 45 -- modules/ctrl/Makefile | 24 - modules/ctrl/inc/start.h | 43 -- modules/ctrl/src/start.c | 116 ---- modules/ctrl/tmp/Makefile | 53 -- modules/game/Makefile | 24 - modules/game/inc/game.h | 95 --- modules/game/inc/game_iface.h | 153 ----- modules/game/src/game.c | 386 ----------- modules/game/src/game_iface.c | 546 --------------- modules/game/tmp/Makefile | 73 -- modules/menu/Makefile | 24 - modules/menu/inc/menu_clui.h | 27 - modules/menu/inc/menu_gui.h | 56 -- modules/menu/inc/menu_iface.h | 67 -- modules/menu/inc/menu_tui.h | 27 - modules/menu/inc/parser.h | 27 - modules/menu/src/menu_clui.c | 240 ------- modules/menu/src/menu_gui.c | 991 ---------------------------- modules/menu/src/menu_iface.c | 133 ---- modules/menu/src/menu_tui.c | 423 ------------ modules/menu/src/parser.c | 226 ------- modules/menu/tmp/Makefile | 165 ----- modules/player/Makefile | 24 - modules/player/inc/player_clui.h | 72 -- modules/player/inc/player_gui.h | 79 --- modules/player/inc/player_iface.h | 93 --- modules/player/inc/player_tui.h | 114 ---- modules/player/src/player_clui.c | 500 -------------- modules/player/src/player_gui.c | 946 -------------------------- modules/player/src/player_iface.c | 419 ------------ modules/player/src/player_tui.c | 858 ------------------------ modules/player/tmp/Makefile | 102 --- modules/save/Makefile | 24 - modules/save/inc/save.h | 63 -- modules/save/inc/score.h | 70 -- modules/save/src/save.c | 255 ------- modules/save/src/score.c | 311 --------- modules/save/tmp/Makefile | 67 -- modules/tmp/Makefile | 46 -- modules/xyzzy/Makefile | 24 - modules/xyzzy/inc/xyzzy.h | 31 - modules/xyzzy/src/xyzzy.c | 108 --- modules/xyzzy/tmp/Makefile | 45 -- share/COPYRIGHT.txt | 15 - share/DISCLAIMER.txt | 16 - share/HELP.txt | 41 -- share/LICENSE.txt | 352 ---------- share/README.txt | 119 ---- share/USAGE.txt | 8 - share/mine-sweeper/COPYRIGHT.txt | 15 + share/mine-sweeper/DISCLAIMER.txt | 16 + share/mine-sweeper/HELP.txt | 41 ++ share/mine-sweeper/LICENSE.txt | 352 ++++++++++ share/mine-sweeper/README.txt | 119 ++++ share/mine-sweeper/USAGE.txt | 8 + share/mine-sweeper/saved/saved_000.mine | 24 + share/saved/saved_000.mine | 24 - src/about/about.c | 95 +++ src/ctrl/start.c | 110 +++ src/game/core.c | 383 +++++++++++ src/game/iface.c | 543 +++++++++++++++ src/main.c | 45 +- src/menu/clui.c | 243 +++++++ src/menu/iface.c | 101 +++ src/menu/parser.c | 225 +++++++ src/menu/tui.c | 413 ++++++++++++ src/player/clui.c | 501 ++++++++++++++ src/player/iface.c | 397 +++++++++++ src/player/tui.c | 854 ++++++++++++++++++++++++ src/save/save.c | 238 +++++++ src/save/score.c | 128 ++++ src/xyzzy/xyzzy.c | 108 +++ tmp/Makefile | 120 ++-- tmp/about/Makefile | 53 ++ tmp/ctrl/Makefile | 55 ++ tmp/game/Makefile | 72 ++ tmp/menu/Makefile | 116 ++++ tmp/player/Makefile | 86 +++ tmp/save/Makefile | 74 +++ tmp/xyzzy/Makefile | 52 ++ var/hiscores/hiscores_beginner.mine | 1 - var/hiscores/hiscores_expert.mine | 1 - var/hiscores/hiscores_intermediate.mine | 1 - var/mine-sweeper/hiscores/beginner.mine | 1 + var/mine-sweeper/hiscores/expert.mine | 1 + var/mine-sweeper/hiscores/intermediate.mine | 1 + 112 files changed, 6645 insertions(+), 9307 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .gitmodules mode change 100644 => 100755 COPYING.txt mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.txt mode change 100644 => 100755 bin/Makefile create mode 100755 inc/mine-sweeper/about/about.h create mode 100755 inc/mine-sweeper/ctrl/start.h create mode 100755 inc/mine-sweeper/game/core.h create mode 100755 inc/mine-sweeper/game/iface.h create mode 100755 inc/mine-sweeper/menu/clui.h create mode 100755 inc/mine-sweeper/menu/iface.h create mode 100755 inc/mine-sweeper/menu/parser.h create mode 100755 inc/mine-sweeper/menu/tui.h create mode 100755 inc/mine-sweeper/player/clui.h create mode 100755 inc/mine-sweeper/player/iface.h create mode 100755 inc/mine-sweeper/player/tui.h create mode 100755 inc/mine-sweeper/save/save.h create mode 100755 inc/mine-sweeper/save/score.h create mode 100755 inc/mine-sweeper/xyzzy/xyzzy.h delete mode 100644 modules/Makefile delete mode 100644 modules/about/Makefile delete mode 100644 modules/about/inc/about.h delete mode 100644 modules/about/src/about.c delete mode 100644 modules/about/tmp/Makefile delete mode 100644 modules/ctrl/Makefile delete mode 100644 modules/ctrl/inc/start.h delete mode 100644 modules/ctrl/src/start.c delete mode 100644 modules/ctrl/tmp/Makefile delete mode 100644 modules/game/Makefile delete mode 100644 modules/game/inc/game.h delete mode 100644 modules/game/inc/game_iface.h delete mode 100644 modules/game/src/game.c delete mode 100644 modules/game/src/game_iface.c delete mode 100644 modules/game/tmp/Makefile delete mode 100644 modules/menu/Makefile delete mode 100644 modules/menu/inc/menu_clui.h delete mode 100644 modules/menu/inc/menu_gui.h delete mode 100644 modules/menu/inc/menu_iface.h delete mode 100644 modules/menu/inc/menu_tui.h delete mode 100644 modules/menu/inc/parser.h delete mode 100644 modules/menu/src/menu_clui.c delete mode 100644 modules/menu/src/menu_gui.c delete mode 100644 modules/menu/src/menu_iface.c delete mode 100644 modules/menu/src/menu_tui.c delete mode 100644 modules/menu/src/parser.c delete mode 100644 modules/menu/tmp/Makefile delete mode 100644 modules/player/Makefile delete mode 100644 modules/player/inc/player_clui.h delete mode 100644 modules/player/inc/player_gui.h delete mode 100644 modules/player/inc/player_iface.h delete mode 100644 modules/player/inc/player_tui.h delete mode 100644 modules/player/src/player_clui.c delete mode 100644 modules/player/src/player_gui.c delete mode 100644 modules/player/src/player_iface.c delete mode 100644 modules/player/src/player_tui.c delete mode 100644 modules/player/tmp/Makefile delete mode 100644 modules/save/Makefile delete mode 100644 modules/save/inc/save.h delete mode 100644 modules/save/inc/score.h delete mode 100644 modules/save/src/save.c delete mode 100644 modules/save/src/score.c delete mode 100644 modules/save/tmp/Makefile delete mode 100644 modules/tmp/Makefile delete mode 100644 modules/xyzzy/Makefile delete mode 100644 modules/xyzzy/inc/xyzzy.h delete mode 100644 modules/xyzzy/src/xyzzy.c delete mode 100644 modules/xyzzy/tmp/Makefile delete mode 100644 share/COPYRIGHT.txt delete mode 100644 share/DISCLAIMER.txt delete mode 100644 share/HELP.txt delete mode 100644 share/LICENSE.txt delete mode 100644 share/README.txt delete mode 100644 share/USAGE.txt create mode 100755 share/mine-sweeper/COPYRIGHT.txt create mode 100755 share/mine-sweeper/DISCLAIMER.txt create mode 100755 share/mine-sweeper/HELP.txt create mode 100755 share/mine-sweeper/LICENSE.txt create mode 100755 share/mine-sweeper/README.txt create mode 100755 share/mine-sweeper/USAGE.txt create mode 100755 share/mine-sweeper/saved/saved_000.mine delete mode 100644 share/saved/saved_000.mine create mode 100755 src/about/about.c create mode 100755 src/ctrl/start.c create mode 100755 src/game/core.c create mode 100755 src/game/iface.c mode change 100644 => 100755 src/main.c create mode 100755 src/menu/clui.c create mode 100755 src/menu/iface.c create mode 100755 src/menu/parser.c create mode 100755 src/menu/tui.c create mode 100755 src/player/clui.c create mode 100755 src/player/iface.c create mode 100755 src/player/tui.c create mode 100755 src/save/save.c create mode 100755 src/save/score.c create mode 100755 src/xyzzy/xyzzy.c mode change 100644 => 100755 tmp/Makefile create mode 100755 tmp/about/Makefile create mode 100755 tmp/ctrl/Makefile create mode 100755 tmp/game/Makefile create mode 100755 tmp/menu/Makefile create mode 100755 tmp/player/Makefile create mode 100755 tmp/save/Makefile create mode 100755 tmp/xyzzy/Makefile delete mode 100644 var/hiscores/hiscores_beginner.mine delete mode 100644 var/hiscores/hiscores_expert.mine delete mode 100644 var/hiscores/hiscores_intermediate.mine create mode 100755 var/mine-sweeper/hiscores/beginner.mine create mode 100755 var/mine-sweeper/hiscores/expert.mine create mode 100755 var/mine-sweeper/hiscores/intermediate.mine diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/COPYING.txt b/COPYING.txt old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 0c5d366..1ce22b8 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -#!/usr/bin/make -f +#! /usr/bin/make -f -VERSION = 4 -PATCHLEVEL = -SUBLEVEL = -EXTRAVERSION = ~b2 -NAME = graphic +VERSION = 5 +PATCHLEVEL = ~a1 +SUBLEVEL = +EXTRAVERSION = +NAME = export VERSION export PATCHLEVEL @@ -71,125 +71,106 @@ PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$( export PROGRAMVERSION ################################################################################ -OS = linux -TST = false -DBG = false +# directories + +MAIN_DIR = $(CURDIR) + +LIBALX_DIR = $(CURDIR)/libalx/ +LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/libalx/ -export OS -export TST -export DBG +BIN_DIR = $(CURDIR)/bin/ +INC_DIR = $(CURDIR)/inc/ +SRC_DIR = $(CURDIR)/src/ +TMP_DIR = $(CURDIR)/tmp/ + +export MAIN_DIR +export LIBALX_DIR +export LIBALX_INC_DIR +export LIBALX_LIB_DIR +export BIN_DIR +export INC_DIR +export SRC_DIR +export TMP_DIR + +# FIXME: Set local or not local when building a package +INSTALL_BIN_DIR = /usr/local/bin/ +#INSTALL_BIN_DIR = /usr/bin/ +INSTALL_SHARE_DIR = /usr/local/share/ +#INSTALL_SHARE_DIR = /usr/share/ +INSTALL_VAR_DIR = /var/local/ +#INSTALL_VAR_DIR = /var/lib/ ################################################################################ # Make variables (CC, etc...) - CC = gcc - AS = as - AR = ar - LD = ld +CC = gcc +AS = as +AR = ar +LD = ld +SZ = size --format=SysV export CC export AS export AR export LD +export SZ ################################################################################ # cflags -CFLAGS_STD = -std=c11 +CFLAGS_STD = -std=c17 CFLAGS_STD += -Wpedantic CFLAGS_OPT = -O3 CFLAGS_OPT += -march=native +CFLAGS_OPT += -flto CFLAGS_W = -Wall +CFLAGS_W += -Wextra +CFLAGS_W += -Wstrict-prototypes CFLAGS_W += -Werror -#CFLAGS_W += -Wstrict-prototypes CFLAGS_W += -Wno-error=format-truncation #CFLAGS_W += -Wno-error=unused-function #CFLAGS_W += -Wno-error=unused-parameter CFLAGS_PKG = `pkg-config --cflags ncurses` -CFLAGS_PKG += `pkg-config --cflags gtk+-2.0` +CFLAGS_PKG += -I $(LIBALX_INC_DIR) CFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" CFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" -CFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" CFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" -CFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" -ifeq ($(OS), linux) - CFLAGS_D += -D OS_LINUX -else ifeq ($(OS), win) - CFLAGS_D += -D OS_WIN -endif +CFLAGS_I = -I $(INC_DIR) CFLAGS = $(CFLAGS_STD) CFLAGS += $(CFLAGS_OPT) CFLAGS += $(CFLAGS_W) CFLAGS += $(CFLAGS_PKG) CFLAGS += $(CFLAGS_D) +CFLAGS += $(CFLAGS_I) export CFLAGS ################################################################################ # libs -LIBS_STATIC = -static - LIBS_STD = -l m +LIBS_OPT = -O3 +LIBS_OPT += -march=native +LIBS_OPT += -flto +LIBS_OPT += -fuse-linker-plugin + LIBS_PKG = `pkg-config --libs ncurses` -LIBS_PKG += `pkg-config --libs gtk+-2.0` -ifeq ($(OS), linux) - LIBS = $(LIBS_STD) $(LIBS_PKG) -else ifeq ($(OS), win) - LIBS = $(LIBS_STD) $(LIBS_STATIC) $(LIBS_PKG) -endif +LIBS = $(LIBS_STD) +LIBS += $(LIBS_OPT) +LIBS += $(LIBS_PKG) export LIBS -################################################################################ -# directories - -MAIN_DIR = $(CURDIR) - -LIBALX_DIR = $(CURDIR)/libalx/ -MODULES_DIR = $(CURDIR)/modules/ -TMP_DIR = $(CURDIR)/tmp/ -BIN_DIR = $(CURDIR)/bin/ - -export MAIN_DIR -export LIBALX_DIR -export MODULES_DIR - -# FIXME: Set local or not local when building a package -ifeq ($(OS), linux) - INSTALL_BIN_DIR = /usr/local/games/ -# INSTALL_BIN_DIR = /usr/games/ - INSTALL_SHARE_DIR = /usr/local/share/ -# INSTALL_SHARE_DIR = /usr/share/ - SHARE_DIR = mine-sweeper/ - INSTALL_VAR_DIR = /var/local/ -# INSTALL_VAR_DIR = /var/games/ - VAR_DIR = mine-sweeper/ -else ifeq ($(OS), win) - INSTALL_DIR = c:/Program files (x86)/ - INSTALL_SHARE_DIR = $(INSTALL_DIR)/mine-sweeper/ - SHARE_DIR = share/ - INSTALL_VAR_DIR = $(INSTALL_DIR)/mine-sweeper/ - VAR_DIR = var/ -endif - -export INSTALL_DIR -export INSTALL_SHARE_DIR -export SHARE_DIR - ################################################################################ # executables -ifeq ($(OS), linux) - BIN_NAME = mine-sweeper -else ifeq ($(OS), win) - BIN_NAME = mine-sweeper.exe -endif +BIN_NAME = mine-sweeper export BIN_NAME @@ -199,60 +180,52 @@ export BIN_NAME # That's the default target when none is given on the command line PHONY := all -all: libalx modules main binary +all: bin PHONY += libalx libalx: - @echo ' MAKE libalx' + @echo " MAKE $@" $(Q)$(MAKE) base -C $(LIBALX_DIR) - $(Q)$(MAKE) io -C $(LIBALX_DIR) - $(Q)$(MAKE) curses -C $(LIBALX_DIR) + $(Q)$(MAKE) ncurses -C $(LIBALX_DIR) @echo -PHONY += modules -modules: libalx - @echo ' MAKE modules' - $(Q)$(MAKE) -C $(MODULES_DIR) +PHONY += tmp +tmp: + @echo " MAKE $@" + $(Q)$(MAKE) -C $(TMP_DIR) @echo -PHONY += main -main: libalx modules - @echo ' MAKE main' - $(Q)$(MAKE) -C $(TMP_DIR) - @echo - -PHONY += binary -binary: main - @echo ' MAKE bin' - $(Q)$(MAKE) -C $(BIN_DIR) +PHONY += bin +bin: tmp libalx + @echo " MAKE $@" + $(Q)$(MAKE) -C $(BIN_DIR) @echo PHONY += install install: uninstall @echo " Install:" - @echo " MKDIR $(INSTALL_BIN_DIR)/" + @echo " MKDIR $(DESTDIR)/$(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo " CP -v $(BIN_NAME)" + @echo " CP $(BIN_NAME)" $(Q)cp -v $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " CP -rv share/*" - $(Q)cp -r -v ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - - @echo " MKDIR $(INSTALL_VAR_DIR)/$(VAR_DIR)/" - $(Q)mkdir -p $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ - $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/boards_beginner/ - $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/boards_intermediate/ - $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/boards_expert/ - $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/boards_custom/ - @echo " CP -rv var/*" - $(Q)cp -r -v ./var/* $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ - @echo " CHOWN $(INSTALL_VAR_DIR)/$(VAR_DIR)/" - $(Q)chown root:games -R $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ - @echo " CHMOD $(INSTALL_VAR_DIR)/$(VAR_DIR)/" - $(Q)chmod 664 -R $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ - $(Q)chmod +X -R $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ + @echo " MKDIR $(DESTDIR)/$(INSTALL_SHARE_DIR)/mine-sweeper/" + $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/mine-sweeper/ + @echo " CP -r share/mine-sweeper/*" + $(Q)cp -r -v ./share/mine-sweeper/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/mine-sweeper/ + @echo " MKDIR $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/" + $(Q)mkdir -p $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ + $(Q)mkdir -p $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/boards/beginner/ + $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/boards/intermediate/ + $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/boards/expert/ + $(Q)mkdir $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/boards/custom/ + @echo " CP -rv var/mine-sweeper/*" + $(Q)cp -r -v ./var/mine-sweeper/* $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ + @echo " CHOWN $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/" + $(Q)chown root:games -R $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ + @echo " CHMOD $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/" + $(Q)chmod 664 -R $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ + $(Q)chmod +X -R $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ @echo " Done" @echo @@ -261,25 +234,22 @@ uninstall: @echo " Clean old installations:" @echo " RM bin" $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) - @echo " RM -r $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " RM -r $(INSTALL_VAR_DIR)/$(VAR_DIR)/" - $(Q)rm -f -r $(DESTDIR)/$(INSTALL_VAR_DIR)/$(VAR_DIR)/ + @echo " RM -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/mine-sweeper/" + $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/mine-sweeper/ + @echo " RM -r $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/" + $(Q)rm -f -r $(DESTDIR)/$(INSTALL_VAR_DIR)/mine-sweeper/ @echo " Done" @echo PHONY += clean clean: - @echo ' CLEAN modules' - $(Q)$(MAKE) clean -C $(MODULES_DIR) - @echo ' CLEAN tmp' - $(Q)$(MAKE) clean -C $(TMP_DIR) - @echo ' CLEAN bin' - $(Q)$(MAKE) clean -C $(BIN_DIR) - @echo + @echo " RM *.o *.s *.a $(BIN_NAME)" + $(Q)find $(TMP_DIR) -type f -name '*.o' -exec rm '{}' '+' + $(Q)find $(TMP_DIR) -type f -name '*.s' -exec rm '{}' '+' + $(Q)find $(BIN_DIR) -type f -name '*$(BIN_NAME)' -exec rm '{}' '+' -PHONY += mrproper -mrproper: clean +PHONY += distclean +distclean: clean @echo ' CLEAN libalx' $(Q)$(MAKE) clean -C $(LIBALX_DIR) @echo @@ -288,14 +258,13 @@ PHONY += help help: @echo 'Cleaning targets:' @echo ' clean - Remove all generated files' - @echo ' mrproper - Remove all generated files (including libraries)' + @echo ' distclean - Remove all generated files (including libraries)' @echo '' @echo 'Other generic targets:' @echo ' all - Build all targets marked with [*]' @echo '* libalx - Build the libalx library' - @echo '* modules - Build all modules' - @echo '* object - Build the main object' - @echo '* binary - Build the binary' + @echo '* tmp - Compile all files' + @echo '* bin - Build the binary' @echo ' install - Install the program into the filesystem' @echo ' uninstall - Uninstall the program off the filesystem' @echo '' @@ -309,8 +278,6 @@ help: .PHONY: $(PHONY) - - ################################################################################ ######## End of file ########################################################### ################################################################################ diff --git a/README.txt b/README.txt old mode 100644 new mode 100755 diff --git a/bin/Makefile b/bin/Makefile old mode 100644 new mode 100755 index 76d6c44..ef72a44 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,45 +1,61 @@ -# -*- MakeFile -*- +#! /usr/bin/make -f -# directories - -LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/ - -MODULES_TMP_DIR = $(MODULES_DIR)/tmp/ - -TMP_DIR = $(MAIN_DIR)/tmp/ - -# dependencies -_ALL = $(BIN_NAME) $(BIN_NAME).exe +# MACRO = substitute with this -ALL = $(BIN_NAME) +# directories -MAIN_OBJ_MODULES = modules.o -MAIN_OBJS = $(TMP_DIR)/main.o \ - $(patsubst %,$(LIBALX_TMP_DIR)/%,$(MAIN_OBJ_LIBALX)) \ - $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) +OBJS = \ + $(TMP_DIR)/main.o \ + $(TMP_DIR)/about/about.o \ + $(TMP_DIR)/ctrl/start.o \ + $(TMP_DIR)/game/core.o \ + $(TMP_DIR)/game/iface.o \ + $(TMP_DIR)/menu/parser.o \ + $(TMP_DIR)/menu/clui.o \ + $(TMP_DIR)/menu/tui.o \ + $(TMP_DIR)/menu/iface.o \ + $(TMP_DIR)/player/clui.o \ + $(TMP_DIR)/player/tui.o \ + $(TMP_DIR)/player/iface.o \ + $(TMP_DIR)/save/save.o \ + $(TMP_DIR)/save/score.o \ + $(TMP_DIR)/xyzzy/xyzzy.o +DEPS_LIBS = \ + $(LIBALX_LIB_DIR)/libalx-ncurses.a \ + $(LIBALX_LIB_DIR)/libalx-base.a + +ALL = $(BIN_NAME) size # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) \ - -l alx-curses \ - -l alx-io \ - -l alx-base -STATIC_LIBS = $(STATIC_LIB_LIBALX) +STATIC_LIBS = -L $(LIBALX_LIB_DIR) \ + -l alx-ncurses \ + -l alx-base # target: dependencies # action +PHONY := all all: $(ALL) -$(BIN_NAME): $(MAIN_OBJS) - @echo " CC $@" - $(Q)$(CC) $^ -o $@ $(STATIC_LIBS) $(LIBS) +$(BIN_NAME): $(OBJS) $(DEPS_LIBS) + @echo " CC $@" + $(Q)$(CC) $(OBJS) -o $@ $(STATIC_LIBS) $(LIBS) + +size: $(BIN_NAME) + @echo " SZ $(BIN_NAME)" + $(Q)$(SZ) $(BIN_NAME) clean: - $(Q)rm -f $(_ALL) + @echo " RM $(ALL)" + $(Q)rm -f $(ALL) + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) ################################################################################ ######## End of file ########################################################### diff --git a/inc/mine-sweeper/about/about.h b/inc/mine-sweeper/about/about.h new file mode 100755 index 0000000..8be4cce --- /dev/null +++ b/inc/mine-sweeper/about/about.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_ABOUT_H +#define MSW_ABOUT_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define PROG_NAME "mine-sweeper" +#define PROG_YEAR "2015" + +#define SHARE_DIR "" INSTALL_SHARE_DIR "/mine-sweeper/" +#define SHARE_COPYRIGHT_FILE "" SHARE_DIR "/COPYRIGHT.txt" +#define SHARE_DISCLAIMER_FILE "" SHARE_DIR "/DISCLAIMER.txt" +#define SHARE_HELP_FILE "" SHARE_DIR "/HELP.txt" +#define SHARE_LICENSE_FILE "" SHARE_DIR "/LICENSE.txt" +#define SHARE_USAGE_FILE "" SHARE_DIR "/USAGE.txt" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void print_share_file (int share_file); +void print_version (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/ctrl/start.h b/inc/mine-sweeper/ctrl/start.h new file mode 100755 index 0000000..224999b --- /dev/null +++ b/inc/mine-sweeper/ctrl/start.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef MSW_START_H + # define MSW_START_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Start_Mode { + START_FOO = 0, + START_RAND, + START_LOAD + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int start_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void start_switch (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* start.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/game/core.h b/inc/mine-sweeper/game/core.h new file mode 100755 index 0000000..b07e38f --- /dev/null +++ b/inc/mine-sweeper/game/core.h @@ -0,0 +1,109 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_GAME_CORE_H +#define MSW_GAME_CORE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include +#include + +#include "mine-sweeper/game/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Game_Mine_Board { + GAME_MINE_NO = 0, + GAME_MINE_YES = 9 +}; + +enum Game_Usr_Board { + GAME_USR_KBOOM = -1, + GAME_USR_HIDDEN, + GAME_USR_CLEAR, + GAME_USR_FLAG, + GAME_USR_POSSIBLE +}; + +enum Game_Action { + GAME_ACT_FOO = 0, + GAME_ACT_STEP, + GAME_ACT_FLAG, + GAME_ACT_FLAG_POSSIBLE, + GAME_ACT_RM_FLAG +}; + +enum Game_State { + GAME_STATE_PLAYING = 0, + GAME_STATE_SAFE, + GAME_STATE_GAMEOVER +}; + + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Game_Board { + ptrdiff_t rows; + ptrdiff_t cols; + int mines; + int gnd [ROWS_MAX] [COLS_MAX]; + int usr [ROWS_MAX] [COLS_MAX]; + int flags; + int clr; + int state; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern struct Game_Board game_board; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void game_init (void); +void game_init_rand (ptrdiff_t rows, ptrdiff_t cols, int mines, + ptrdiff_t pos_row, ptrdiff_t pos_col); +int game_init_load (ptrdiff_t *rows, ptrdiff_t *cols); +void game_action (int action, ptrdiff_t row, ptrdiff_t col); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* mine-sweeper/game/core.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/game/iface.h b/inc/mine-sweeper/game/iface.h new file mode 100755 index 0000000..c5c0277 --- /dev/null +++ b/inc/mine-sweeper/game/iface.h @@ -0,0 +1,175 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_GAME_IFACE_H +#define MSW_GAME_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define ROWS_MAX (999) +#define COLS_MAX (999) +#define CHEATED (-1) + +#define GAME_IFACE_LVL_BEGINNER_ROWS (8) +#define GAME_IFACE_LVL_BEGINNER_COLS (8) +#define GAME_IFACE_LVL_BEGINNER_MINES (10) + +#define GAME_IFACE_LVL_INTERMEDIATE_ROWS (16) +#define GAME_IFACE_LVL_INTERMEDIATE_COLS (16) +#define GAME_IFACE_LVL_INTERMEDIATE_MINES (40) + +#define GAME_IFACE_LVL_EXPERT_ROWS (16) +#define GAME_IFACE_LVL_EXPERT_COLS (30) +#define GAME_IFACE_LVL_EXPERT_MINES (99) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Game_Iface_Level { + GAME_IFACE_LVL_BEGINNER = 0, + GAME_IFACE_LVL_INTERMEDIATE, + GAME_IFACE_LVL_EXPERT, + GAME_IFACE_LVL_EXPERT_INV, + GAME_IFACE_LVL_CUSTOM +}; + +enum Game_Iface_Visible_Board { + GAME_IFACE_VIS_FOO = -1, + GAME_IFACE_VIS_KBOOM, + GAME_IFACE_VIS_HIDDEN_FIELD, + GAME_IFACE_VIS_HIDDEN_MINE, + GAME_IFACE_VIS_HIDDEN_SAFE, + GAME_IFACE_VIS_SAFE_MINE, + GAME_IFACE_VIS_0, + GAME_IFACE_VIS_1, + GAME_IFACE_VIS_2, + GAME_IFACE_VIS_3, + GAME_IFACE_VIS_4, + GAME_IFACE_VIS_5, + GAME_IFACE_VIS_6, + GAME_IFACE_VIS_7, + GAME_IFACE_VIS_8, + GAME_IFACE_VIS_FLAG, + GAME_IFACE_VIS_FLAG_FALSE, + GAME_IFACE_VIS_POSSIBLE, + GAME_IFACE_VIS_POSSIBLE_FALSE +}; + +/* Needs to be the same as 'enum Game_Usr_Board' in 'game.h' */ +enum Game_Iface_Usr_Board { + GAME_IFACE_USR_KBOOM = -1, + GAME_IFACE_USR_HIDDEN, + GAME_IFACE_USR_CLEAR, + GAME_IFACE_USR_FLAG, + GAME_IFACE_USR_POSSIBLE +}; + +/* Needs to be the same as 'enum Game_Action' in 'game.h' */ +enum Game_Iface_Action_Play { + GAME_IFACE_GAME_ACT_FOO = 0, + GAME_IFACE_GAME_ACT_STEP, + GAME_IFACE_GAME_ACT_FLAG, + GAME_IFACE_GAME_ACT_FLAG_POSSIBLE, + GAME_IFACE_GAME_ACT_RM_FLAG +}; + +enum Game_Iface_Action { + GAME_IFACE_ACT_FOO, + GAME_IFACE_ACT_PLAY, + GAME_IFACE_ACT_PAUSE, + GAME_IFACE_ACT_SAVE, + GAME_IFACE_ACT_XYZZY_ON, + GAME_IFACE_ACT_XYZZY_OFF, + GAME_IFACE_ACT_XYZZY_LIN, + GAME_IFACE_ACT_XYZZY_P, + GAME_IFACE_ACT_XYZZY_NP, + GAME_IFACE_ACT_QUIT +}; + +enum Game_Iface_State { + GAME_IFACE_STATE_PLAYING, + GAME_IFACE_STATE_SAFE, + GAME_IFACE_STATE_GAMEOVER, + + GAME_IFACE_STATE_PAUSE, + GAME_IFACE_STATE_CHEATED, + GAME_IFACE_STATE_XYZZY, + GAME_IFACE_STATE_QUIT, + + GAME_IFACE_STATE_FOO +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Game_Iface_Out { + ptrdiff_t rows; + ptrdiff_t cols; + int mines; + int visible [ROWS_MAX] [COLS_MAX]; + int usr [ROWS_MAX] [COLS_MAX]; + int flags; + int clr; + int state; +}; + +struct Game_Iface_Score { + int level; + int time; + int clicks; +}; + +struct Game_Iface_In { + int action; + int act_game [ROWS_MAX] [COLS_MAX]; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void game_iface_init_rand(int level, ptrdiff_t pos_row, ptrdiff_t pos_col); +void game_iface_init_load(void); +void game_iface (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* mine-sweeper/game/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/menu/clui.h b/inc/mine-sweeper/menu/clui.h new file mode 100755 index 0000000..69060a5 --- /dev/null +++ b/inc/mine-sweeper/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/inc/mine-sweeper/menu/iface.h b/inc/mine-sweeper/menu/iface.h new file mode 100755 index 0000000..ca9200f --- /dev/null +++ b/inc/mine-sweeper/menu/iface.h @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_MENU_IFACE_H +#define MSW_MENU_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include +#include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI, + MENU_IFACE_GUI + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct Menu_Iface_Variables { + int level; + ptrdiff_t rows; + ptrdiff_t cols; + double p; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern bool flag_exit; +extern int menu_iface_mode; +extern struct Menu_Iface_Variables menu_iface_variables; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void menu_iface_init (void); +void menu_iface_board (int *level, ptrdiff_t *rows, ptrdiff_t *cols, + int *mines); +void menu_iface (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/menu/parser.h b/inc/mine-sweeper/menu/parser.h new file mode 100755 index 0000000..38fac23 --- /dev/null +++ b/inc/mine-sweeper/menu/parser.h @@ -0,0 +1,27 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef MSW_PARSER_H + # define MSW_PARSER_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/menu/tui.h b/inc/mine-sweeper/menu/tui.h new file mode 100755 index 0000000..71e3104 --- /dev/null +++ b/inc/mine-sweeper/menu/tui.h @@ -0,0 +1,27 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef MSW_MENU_TUI_H + # define MSW_MENU_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_tui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/player/clui.h b/inc/mine-sweeper/player/clui.h new file mode 100755 index 0000000..df02a85 --- /dev/null +++ b/inc/mine-sweeper/player/clui.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_PLAYER_CLUI_H +#define MSW_PLAYER_CLUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_CLUI_Char { + PLAYER_CLUI_CHAR_ERROR = 'X', + PLAYER_CLUI_CHAR_KBOOM = '#', + PLAYER_CLUI_CHAR_HIDDEN_FIELD = '+', + PLAYER_CLUI_CHAR_HIDDEN_MINE = '*', + PLAYER_CLUI_CHAR_HIDDEN_SAFE = '-', + PLAYER_CLUI_CHAR_SAFE_MINE = 'v', + PLAYER_CLUI_CHAR_0 = ' ', + PLAYER_CLUI_CHAR_1 = '1', + PLAYER_CLUI_CHAR_2 = '2', + PLAYER_CLUI_CHAR_3 = '3', + PLAYER_CLUI_CHAR_4 = '4', + PLAYER_CLUI_CHAR_5 = '5', + PLAYER_CLUI_CHAR_6 = '6', + PLAYER_CLUI_CHAR_7 = '7', + PLAYER_CLUI_CHAR_8 = '8', + PLAYER_CLUI_CHAR_FLAG = '!', + PLAYER_CLUI_CHAR_FLAG_FALSE = 'F', + PLAYER_CLUI_CHAR_POSSIBLE = '?', + PLAYER_CLUI_CHAR_POSSIBLE_FALSE = 'f' +}; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +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_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]); +void player_clui_score_name (char player_name[static restrict BUFSIZ]); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* player_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/player/iface.h b/inc/mine-sweeper/player/iface.h new file mode 100755 index 0000000..79bdb7a --- /dev/null +++ b/inc/mine-sweeper/player/iface.h @@ -0,0 +1,112 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_PLAYER_IFACE_H +#define MSW_PLAYER_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include +#include + +#include "mine-sweeper/game/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_Iface_Mode { + PLAYER_IFACE_FOO = 0, + PLAYER_IFACE_CLUI, + PLAYER_IFACE_TUI, + PLAYER_IFACE_GUI +}; + +enum Player_Iface_Action { + PLAYER_IFACE_ACT_FOO, + PLAYER_IFACE_ACT_STEP, + PLAYER_IFACE_ACT_FLAG, + PLAYER_IFACE_ACT_FLAG_POSSIBLE, + PLAYER_IFACE_ACT_RM_FLAG, + + PLAYER_IFACE_ACT_PAUSE, + PLAYER_IFACE_ACT_SAVE, + PLAYER_IFACE_ACT_XYZZY_ON, + PLAYER_IFACE_ACT_XYZZY_OFF, + PLAYER_IFACE_ACT_XYZZY_LIN, + PLAYER_IFACE_ACT_XYZZY_P, + PLAYER_IFACE_ACT_XYZZY_NP, + PLAYER_IFACE_ACT_QUIT, + + PLAYER_IFACE_ACT_MOVE_UP, + PLAYER_IFACE_ACT_MOVE_DOWN, + PLAYER_IFACE_ACT_MOVE_RIGHT, + PLAYER_IFACE_ACT_MOVE_LEFT, + PLAYER_IFACE_ACT_HIGHLIGHT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Player_Iface_Position { + int rows; + int cols; + int row; + int col; + int highlight; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int player_iface_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void player_iface_init (ptrdiff_t rows, ptrdiff_t cols); +int player_iface_start (ptrdiff_t *row, ptrdiff_t *col); +void player_iface (const struct Game_Iface_Out *out, + const struct Game_Iface_Score *score, + struct Game_Iface_In *in); +void player_iface_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]); +void player_iface_score_name (char player_name[static restrict BUFSIZ]); +void player_iface_cleanup (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* mine-sweeper/player/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/player/tui.h b/inc/mine-sweeper/player/tui.h new file mode 100755 index 0000000..71ae32d --- /dev/null +++ b/inc/mine-sweeper/player/tui.h @@ -0,0 +1,113 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_PLAYER_TUI_H +#define MSW_PLAYER_TUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include +#include +#include + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_TUI_Char { + PLAYER_TUI_CHAR_ERROR = 'X', + PLAYER_TUI_CHAR_KBOOM = '#', + PLAYER_TUI_CHAR_HIDDEN_FIELD = '+', + PLAYER_TUI_CHAR_HIDDEN_MINE = '*', + PLAYER_TUI_CHAR_HIDDEN_SAFE = '-', + PLAYER_TUI_CHAR_SAFE_MINE = 'v', + PLAYER_TUI_CHAR_0 = ' ', + PLAYER_TUI_CHAR_1 = '1', + PLAYER_TUI_CHAR_2 = '2', + PLAYER_TUI_CHAR_3 = '3', + PLAYER_TUI_CHAR_4 = '4', + PLAYER_TUI_CHAR_5 = '5', + PLAYER_TUI_CHAR_6 = '6', + PLAYER_TUI_CHAR_7 = '7', + PLAYER_TUI_CHAR_8 = '8', + PLAYER_TUI_CHAR_FLAG = '!', + PLAYER_TUI_CHAR_FLAG_FALSE = 'F', + PLAYER_TUI_CHAR_POSSIBLE = '?', + PLAYER_TUI_CHAR_POSSIBLE_FALSE = 'f' + }; + + enum Color_Pairs { + /* Clear */ + PAIR_1 = 1, + PAIR_2, + PAIR_3, + PAIR_4, + PAIR_5, + PAIR_6, + PAIR_7, + PAIR_8, + PAIR_BLANK, + /* Hidden */ + PAIR_MINE, + PAIR_HIDDEN, + /* Possible */ + PAIR_fail, + PAIR_POSSIBLE, + /* Flag */ + PAIR_FAIL, + PAIR_FLAG, + /* kboom */ + PAIR_KBOOM, + /* Highlight */ + PAIR_HILITE, + + /* Terminal colors */ + PAIR_TERM + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern bool flag_color; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void player_tui_init (ptrdiff_t rows, ptrdiff_t cols); + +int player_tui_start (const struct Player_Iface_Position *position, + const char *title, const char *subtitle, + int *action); + +int player_tui (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position, + const char *title, const char *subtitle, + int *action); + +void player_tui_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]); +void player_tui_score_name (char player_name[static restrict BUFSIZ]); +void player_tui_cleanup (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* player_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/save/save.h b/inc/mine-sweeper/save/save.h new file mode 100755 index 0000000..b50cbad --- /dev/null +++ b/inc/mine-sweeper/save/save.h @@ -0,0 +1,57 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_SAVE_H +#define MSW_SAVE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include +#include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define ENV_HOME "HOME" + +#define USER_GAME_DIR ".mine-sweeper/" +#define USER_SAVED_DIR ".mine-sweeper/saved/" +#define SAVED_NAME_DEFAULT "saved" +#define FILE_EXTENSION ".mine" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char home_path [FILENAME_MAX]; +extern char user_game_path [FILENAME_MAX]; +extern char saved_path [FILENAME_MAX]; +extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void save_init (void); +void save_clr (void); +int load_game_file (void); +void save_game_file (char *filepath); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/save/score.h b/inc/mine-sweeper/save/score.h new file mode 100755 index 0000000..41ecb96 --- /dev/null +++ b/inc/mine-sweeper/save/score.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_SCORE_H +#define MSW_SCORE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include + +#include "mine-sweeper/game/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#if defined (OS_LINUX) +# define ENV_HOME "HOME" +#elif defined (OS_WIN) +# define ENV_HOME "USERPROFILE" +#endif + +#define VAR_DIR "" INSTALL_VAR_DIR "/mine-sweeper/" +#define BOARDS_DIR "" VAR_DIR "/boards/" +#define HISCORES_DIR "" VAR_DIR "/hiscores/" +#define BOARDS_BEGINNER_DIR "" VAR_DIR "/boards/beginner/" +#define BOARDS_INTERMEDIATE_DIR "" VAR_DIR "/boards/intermediate/" +#define BOARDS_EXPERT_DIR "" VAR_DIR "/boards/expert/" +#define BOARDS_CUSTOM_DIR "" VAR_DIR "/boards/custom/" +#define HISCORES_BEGINNER_FILE "" VAR_DIR "/hiscores/beginner.mine" +#define HISCORES_INTERMEDIATE_FILE "" VAR_DIR "/hiscores/intermediate.mine" +#define HISCORES_EXPERT_FILE "" VAR_DIR "/hiscores/expert.mine" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void save_score (const struct Game_Iface_Score *game_iface_score); +void print_scores (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* score.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/mine-sweeper/xyzzy/xyzzy.h b/inc/mine-sweeper/xyzzy/xyzzy.h new file mode 100755 index 0000000..fac022a --- /dev/null +++ b/inc/mine-sweeper/xyzzy/xyzzy.h @@ -0,0 +1,37 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef MSW_XYZZY_H +#define MSW_XYZZY_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/game/iface.h" + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void xyzzy_init (void); +int xyzzy_lin (const struct Game_Iface_Out *out, + struct Game_Iface_In *in); +int xyzzy_p (const struct Game_Iface_Out *out, + struct Game_Iface_In *in); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* xyzzy.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/libalx b/libalx index be17660..b23423f 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit be176601c4928dceeb952c1f4810389c5e5a530a +Subproject commit b23423ffcdff33d007fd1faa4474aac9b1ef9399 diff --git a/modules/Makefile b/modules/Makefile deleted file mode 100644 index 4b389d4..0000000 --- a/modules/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -ABOUT_DIR = $(MODULES_DIR)/about/ -CTRL_DIR = $(MODULES_DIR)/ctrl/ -GAME_DIR = $(MODULES_DIR)/game/ -MENU_DIR = $(MODULES_DIR)/menu/ -PLAY_DIR = $(MODULES_DIR)/player/ -SAVE_DIR = $(MODULES_DIR)/save/ -XYZZY_DIR = $(MODULES_DIR)/xyzzy/ - -TMP_DIR = $(MODULES_DIR)/tmp/ - -export ABOUT_DIR -export CTRL_DIR -export GAME_DIR -export MENU_DIR -export PLAY_DIR -export SAVE_DIR -export XYZZY_DIR - -# dependencies - - -# target: dependencies -# action - -PHONY := all -all: - @echo ' MAKE modules: about' - $(Q)$(MAKE) -C $(ABOUT_DIR) - @echo ' MAKE modules: ctrl' - $(Q)$(MAKE) -C $(CTRL_DIR) - @echo ' MAKE modules: game' - $(Q)$(MAKE) -C $(GAME_DIR) - @echo ' MAKE modules: menu' - $(Q)$(MAKE) -C $(MENU_DIR) - @echo ' MAKE modules: play' - $(Q)$(MAKE) -C $(PLAY_DIR) - @echo ' MAKE modules: save' - $(Q)$(MAKE) -C $(SAVE_DIR) - @echo ' MAKE modules: xyzzy' - $(Q)$(MAKE) -C $(XYZZY_DIR) - @echo ' MAKE modules: tmp' - $(Q)$(MAKE) -C $(TMP_DIR) - - -PHONY += clean -clean: - @echo ' RM *.o *.s *.a' - $(Q)find . -type f -name '*.o' -exec rm '{}' '+' - $(Q)find . -type f -name '*.s' -exec rm '{}' '+' - $(Q)find . -type f -name '*.a' -exec rm '{}' '+' - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/Makefile b/modules/about/Makefile deleted file mode 100644 index 42eb4c2..0000000 --- a/modules/about/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(ABOUT_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h deleted file mode 100644 index 804e4a7..0000000 --- a/modules/about/inc/about.h +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_ABOUT_H - # define MSW_ABOUT_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "mine-sweeper" - # define PROG_YEAR "2015" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void about_init (void); -void snprint_share_file (char *dest, int destsize, int share_file); -void print_share_file (int share_file); -void print_version (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/about/src/about.c b/modules/about/src/about.c deleted file mode 100644 index bc21f3e..0000000 --- a/modules/about/src/about.c +++ /dev/null @@ -1,123 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include -/* libalx ------------------------------------------------------------------*/ - #include "libalx/io/alx_file.h" -/* Project -------------------------------------------------------------------*/ - #include "about.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE_TEXT (1048576) - -#if defined OS_LINUX - # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" - # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" -#elif defined OS_WIN - # define BEGINNING "\n________________________________________________________________________________\n" - # define ENDING "________________________________________________________________________________\n\n" -#endif - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void about_init (void) -{ - 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) -{ - char file_name [FILENAME_MAX]; - - switch (share_file) { - case SHARE_COPYRIGHT: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "COPYRIGHT.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_DISCLAIMER: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "DISCLAIMER.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_HELP: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "HELP.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_LICENSE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "LICENSE.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_USAGE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "USAGE.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - } - - alx_snprint_file(dest, destsize, file_name); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - printf("File could not be shown!\n"); -} - -void print_share_file (int share_file) -{ - char str [BUFF_SIZE_TEXT]; - - snprint_share_file(str, BUFF_SIZE_TEXT, share_file); - - printf(BEGINNING); - printf("%s", str); - printf(ENDING); -} - -void print_version (void) -{ - printf("" PROG_NAME " " PROG_VERSION "\n\n"); -} diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile deleted file mode 100644 index b46460f..0000000 --- a/modules/about/tmp/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -INC_DIR = $(ABOUT_DIR)/inc/ -SRC_DIR = $(ABOUT_DIR)/src/ - -# dependencies - -_ALL = about.o -ALL = $(_ALL) about_mod.o - -ABOU_INC_LIBALX = libalx/io/alx_file.h -ABOU_INC = about.h -ABOU_DEPS = $(SRC_DIR)/about.c \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(ABOU_INC_LIBALX)) \ - $(patsubst %,$(INC_DIR)/%,$(ABOU_INC)) -ABOU_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -about_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -about.s: $(ABOU_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@ -about.o: about.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/ctrl/Makefile b/modules/ctrl/Makefile deleted file mode 100644 index 60d7283..0000000 --- a/modules/ctrl/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(CTRL_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h deleted file mode 100644 index 224999b..0000000 --- a/modules/ctrl/inc/start.h +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_START_H - # define MSW_START_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Start_Mode { - START_FOO = 0, - START_RAND, - START_LOAD - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int start_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void start_switch (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* start.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c deleted file mode 100644 index 7a31810..0000000 --- a/modules/ctrl/src/start.c +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include -/* Project -------------------------------------------------------------------*/ - #include "game.h" - #include "game_iface.h" - #include "menu_iface.h" - #include "player_iface.h" - - #include "start.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int start_mode; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void); -static void start_rand (void); -static void start_load (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void start_switch (void) -{ - - switch (start_mode) { - case START_FOO: - start_foo(); - break; - - case START_RAND: - start_rand(); - break; - - case START_LOAD: - start_load(); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void) -{ - - /* empty */ - ; -} - -static void start_rand (void) -{ - int level; - int rows; - int cols; - int mines; - bool fail; - int r; - int c; - - menu_iface_board(&level, &rows, &cols, &mines); - player_iface_init(rows, cols); - fail = player_iface_start(&r, &c); - if (!fail) { - game_init_rand(rows, cols, mines, r, c); - game_iface_init_rand(level, r, c); - /* game loop */ - game_iface(); - } - - player_iface_cleanup(); -} - -static void start_load (void) -{ - int rows; - int cols; - - /* size & game init (sets errno) */ - errno = 0; - game_init_load(&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(); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile deleted file mode 100644 index 82f9c1f..0000000 --- a/modules/ctrl/tmp/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -GAME_INC_DIR = $(GAME_DIR)/inc/ -MENU_INC_DIR = $(MENU_DIR)/inc/ -PLAY_INC_DIR = $(PLAY_DIR)/inc/ - -INC_DIR = $(CTRL_DIR)/inc/ -SRC_DIR = $(CTRL_DIR)/src/ - -# dependencies - -_ALL = start.o -ALL = $(_ALL) ctrl_mod.o - -STRT_INC_GAME = game.h game_iface.h -STRT_INC_MENU = menu_iface.h -STRT_INC_PLAY = player_iface.h -STRT_INC = start.h -STRT_DEPS = $(SRC_DIR)/start.c \ - $(patsubst %,$(GAME_INC_DIR)/%,$(STRT_INC_GAME)) \ - $(patsubst %,$(MENU_INC_DIR)/%,$(STRT_INC_MENU)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(STRT_INC_PLAY)) \ - $(patsubst %,$(INC_DIR)/%,$(STRT_INC)) -STRT_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(MENU_INC_DIR) \ - -I $(PLAY_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -ctrl_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -start.s: $(STRT_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(STRT_INC_DIRS) -S $< -o $@ -start.o: start.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/game/Makefile b/modules/game/Makefile deleted file mode 100644 index 692908e..0000000 --- a/modules/game/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(GAME_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/game/inc/game.h b/modules/game/inc/game.h deleted file mode 100644 index 6f95868..0000000 --- a/modules/game/inc/game.h +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_GAME_H - # define MSW_GAME_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - -/* Project -------------------------------------------------------------------*/ - /* ¡ Need to include these in the Makefile ! */ - /* ROWS_MAX & COLS_MAX */ - #include "game_iface.h" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Game_Mine_Board { - GAME_MINE_NO = 0, - GAME_MINE_YES = 9 - }; - - enum Game_Usr_Board { - GAME_USR_KBOOM = -1, - GAME_USR_HIDDEN, - GAME_USR_CLEAR, - GAME_USR_FLAG, - GAME_USR_POSSIBLE - }; - - enum Game_Action { - GAME_ACT_FOO = 0, - GAME_ACT_STEP, - GAME_ACT_FLAG, - GAME_ACT_FLAG_POSSIBLE, - GAME_ACT_RM_FLAG - }; - - enum Game_State { - GAME_STATE_PLAYING = 0, - GAME_STATE_SAFE, - GAME_STATE_GAMEOVER - }; - - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Game_Board { - int rows; - int cols; - int mines; - int gnd [ROWS_MAX] [COLS_MAX]; - int usr [ROWS_MAX] [COLS_MAX]; - int flags; - int clr; - int state; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern struct Game_Board game_board; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -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); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* game.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/game/inc/game_iface.h b/modules/game/inc/game_iface.h deleted file mode 100644 index 51f0e8c..0000000 --- a/modules/game/inc/game_iface.h +++ /dev/null @@ -1,153 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_GAME_IFACE_H - # define MSW_GAME_IFACE_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # 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_EXPERT_INV, - GAME_IFACE_LEVEL_CUSTOM - }; - - enum Game_Iface_Visible_Board { - GAME_IFACE_VIS_FOO = -1, - GAME_IFACE_VIS_KBOOM, - GAME_IFACE_VIS_HIDDEN_FIELD, - GAME_IFACE_VIS_HIDDEN_MINE, - GAME_IFACE_VIS_HIDDEN_SAFE, - GAME_IFACE_VIS_SAFE_MINE, - GAME_IFACE_VIS_0, - GAME_IFACE_VIS_1, - GAME_IFACE_VIS_2, - GAME_IFACE_VIS_3, - GAME_IFACE_VIS_4, - GAME_IFACE_VIS_5, - GAME_IFACE_VIS_6, - GAME_IFACE_VIS_7, - GAME_IFACE_VIS_8, - GAME_IFACE_VIS_FLAG, - GAME_IFACE_VIS_FLAG_FALSE, - GAME_IFACE_VIS_POSSIBLE, - GAME_IFACE_VIS_POSSIBLE_FALSE - }; - - /* Needs to be the same as 'enum Game_Usr_Board' in 'game.h' */ - enum Game_Iface_Usr_Board { - GAME_IFACE_USR_KBOOM = -1, - GAME_IFACE_USR_HIDDEN, - GAME_IFACE_USR_CLEAR, - GAME_IFACE_USR_FLAG, - GAME_IFACE_USR_POSSIBLE - }; - - /* Needs to be the same as 'enum Game_Action' in 'game.h' */ - enum Game_Iface_Action_Play { - GAME_IFACE_GAME_ACT_FOO = 0, - GAME_IFACE_GAME_ACT_STEP, - GAME_IFACE_GAME_ACT_FLAG, - GAME_IFACE_GAME_ACT_FLAG_POSSIBLE, - GAME_IFACE_GAME_ACT_RM_FLAG - }; - - enum Game_Iface_Action { - GAME_IFACE_ACT_FOO, - GAME_IFACE_ACT_PLAY, - GAME_IFACE_ACT_PAUSE, - GAME_IFACE_ACT_SAVE, - GAME_IFACE_ACT_XYZZY_ON, - GAME_IFACE_ACT_XYZZY_OFF, - GAME_IFACE_ACT_XYZZY_LIN, - GAME_IFACE_ACT_XYZZY_P, - GAME_IFACE_ACT_XYZZY_NP, - GAME_IFACE_ACT_QUIT - }; - - enum Game_Iface_State { - GAME_IFACE_STATE_PLAYING, - GAME_IFACE_STATE_SAFE, - GAME_IFACE_STATE_GAMEOVER, - - GAME_IFACE_STATE_PAUSE, - GAME_IFACE_STATE_CHEATED, - GAME_IFACE_STATE_XYZZY, - GAME_IFACE_STATE_QUIT, - - GAME_IFACE_STATE_FOO - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Game_Iface_Out { - int rows; - int cols; - int mines; - int visible [ROWS_MAX] [COLS_MAX]; - int usr [ROWS_MAX] [COLS_MAX]; - int flags; - int clr; - int state; - }; - - struct Game_Iface_Score { - int level; - int time; - int clicks; - }; - - struct Game_Iface_In { - int action; - int act_game [ROWS_MAX] [COLS_MAX]; - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void game_iface_init_rand (int level, int pos_row, int pos_col); -void game_iface_init_load (void); -void game_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* game_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/game/src/game.c b/modules/game/src/game.c deleted file mode 100644 index 1f912dd..0000000 --- a/modules/game/src/game.c +++ /dev/null @@ -1,386 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - #include - #include - - #include "libalx/alx_seed.h" - - #include "save.h" - - #include "game.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - struct Game_Board game_board; -/* Static --------------------------------------------------------------------*/ - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Init */ -static void game_init_clr (void); -static void game_init_mines (int pos_row, int pos_col); -static void game_init_adjnums (void); - /* Step */ -static void game_step (int r, int c); -static void game_discover (int r, int c); -static void game_discover_recursive (int r, int c); -static void game_big_step (int r, int c); -static int game_count_flags (int r, int c); -static void game_step_recursive (int r, int c); - /* Flag */ -static void game_flag (int r, int c); -static void game_possible (int r, int c); -static void game_rmflag (int r, int c); -static void game_all_flags (int r, int c); -static int game_count_nclear (int r, int c); -static void game_flag_recursive (int r, int c); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -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) -{ - /* size & mines */ - game_board.rows = rows; - game_board.cols = cols; - game_board.mines = mines; - - /* clear */ - game_init_clr(); - - /* place mines */ - game_init_mines(pos_row, pos_col); - - /* calc adjacency numbers */ - game_init_adjnums(); -} - -void game_init_load (int *rows, int *cols) -{ - - 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) -{ - - switch (action) { - case GAME_ACT_STEP: - game_step(row, col); - break; - case GAME_ACT_FLAG: - game_flag(row, col); - break; - case GAME_ACT_FLAG_POSSIBLE: - game_possible(row, col); - break; - case GAME_ACT_RM_FLAG: - game_rmflag(row, col); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Init * * * * * * * - * * * * * * * * * */ -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; - game_board.usr[i][j] = GAME_USR_HIDDEN; - } - } - game_board.flags = 0; - game_board.clr = 0; - game_board.state = GAME_STATE_PLAYING; -} - -static void game_init_mines (int pos_row, int pos_col) -{ - /* place mines */ - int i; - int r; - int c; - - i = 0; - while (i < game_board.mines) { - r = (rand() % game_board.rows); - c = (rand() % game_board.cols); - - if (game_board.gnd[r][c] == GAME_MINE_NO) { - /* first step is safe */ - if (!((r == pos_row) && (c == pos_col))) { - game_board.gnd[r][c] = GAME_MINE_YES; - i++; - } - } - } -} - -static void game_init_adjnums (void) -{ - int r; - 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) { - for (i = r-1; i < r+2; i++) { - for (j = c-1; j < c+2; j++) { - if (i >= 0 && i < game_board.rows) { - if (j >= 0 && j < game_board.cols) { - game_board.gnd[i][j]++; - } - } - } - } - } - } - } -} - -/* * * * * * * * * * - * * * Step * * * * * * * - * * * * * * * * * */ -static void game_step (int r, int c) -{ - - switch (game_board.usr[r][c]) { - case GAME_USR_HIDDEN: - case GAME_USR_POSSIBLE: - game_discover(r, c); - break; - case GAME_USR_CLEAR: - game_big_step(r, c); - break; - } -} - -static void game_discover (int r, int c) -{ - int safe_fields; - - 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; - - } else if (game_board.usr[r][c] != GAME_USR_CLEAR) { - game_board.usr[r][c] = GAME_USR_CLEAR; - game_board.clr++; - - if (game_board.clr == safe_fields) - game_board.state = GAME_STATE_SAFE; - else if (game_board.gnd[r][c] == GAME_MINE_NO) - game_discover_recursive(r, c); - } -} - -static void game_discover_recursive (int r, int c) -{ - int i; - int j; - - for (i = r - 1; i < r + 2; i++) { - for (j = c - 1; j < c + 2; j++) { - if (i >= 0 && i < game_board.rows && - j >= 0 && j < game_board.cols) { - game_discover(i, j); - } - } - } -} - -static void game_big_step (int r, int c) -{ - int cnt; - - cnt = game_count_flags(r, c); - if (cnt && (game_board.gnd[r][c] == cnt)) - game_step_recursive(r, c); -} - -static int game_count_flags (int r, int c) -{ - int cnt; - int i; - int j; - - cnt = 0; - for (i = r - 1; i < r + 2; i++) { - for (j = c - 1; j < c + 2; j++) { - if (i >= 0 && i < game_board.rows && - j >= 0 && j < game_board.cols) { - if (game_board.usr[i][j] == GAME_USR_FLAG) - cnt++; - } - } - } - - return cnt; -} - -static void game_step_recursive (int r, int c) -{ - int i; - int j; - - for (i = r - 1; i < r + 2; i++) { - for (j = c - 1; j < c + 2; j++) { - if (i >= 0 && i < game_board.rows && - j >= 0 && j < game_board.cols) { - switch (game_board.usr[i][j]) { - case GAME_USR_HIDDEN: - case GAME_USR_POSSIBLE: - game_discover(i, j); - break; - } - } - } - } -} - -/* * * * * * * * * * - * * * Flag * * * * * * * - * * * * * * * * * */ -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; - game_board.flags++; - break; - - case GAME_USR_FLAG: - game_board.usr[r][c] = GAME_USR_POSSIBLE; - game_board.flags--; - break; - - case GAME_USR_POSSIBLE: - game_rmflag(r, c); - break; - - case GAME_USR_CLEAR: - game_all_flags(r, c); - break; - } -} - -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; - break; - - case GAME_USR_POSSIBLE: - game_rmflag(r, c); - break; - } -} - -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; - game_board.flags--; - break; - - case GAME_USR_POSSIBLE: - game_board.usr[r][c] = GAME_USR_HIDDEN; - break; - } -} - -static void game_all_flags (int r, int c) -{ - int cnt; - - cnt = game_count_nclear(r, c); - if (cnt && (game_board.gnd[r][c] == cnt)) - game_flag_recursive(r, c); -} - -static int game_count_nclear (int r, int c) -{ - int cnt; - int i; - int j; - - cnt = 0; - for (i = r - 1; i < r + 2; i++) { - for (j = c - 1; j < c + 2; j++) { - if (i >= 0 && i < game_board.rows && - j >= 0 && j < game_board.cols) { - if (game_board.usr[i][j] != GAME_USR_CLEAR) - cnt++; - } - } - } - - return cnt; -} - -static void game_flag_recursive (int r, int c) -{ - int i; - int j; - - for (i = r - 1; i < r + 2; i++) { - for (j = c - 1; j < c + 2; j++) { - if (i >= 0 && i < game_board.rows && - j >= 0 && j < game_board.cols) { - switch (game_board.usr[i][j]) { - case GAME_USR_HIDDEN: - case GAME_USR_POSSIBLE: - game_board.usr[i][j] = GAME_USR_FLAG; - game_board.flags++; - break; - } - } - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/game/src/game_iface.c b/modules/game/src/game_iface.c deleted file mode 100644 index a2df636..0000000 --- a/modules/game/src/game_iface.c +++ /dev/null @@ -1,546 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - - #include "player_iface.h" - #include "save.h" - #include "score.h" - #include "xyzzy.h" - #include "game.h" - - #include "game_iface.h" - - -/****************************************************************************** - ******* 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; -static time_t tim_ini; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Init */ -static void game_iface_init_score (int level); -static void game_iface_init_cheated (void); - /* Actions */ -static void game_iface_act (void); -static void game_iface_playing_act (void); -static void game_iface_xyzzy_act (void); -static void game_iface_cheated_act (void); -static void game_iface_pause_act (void); -static void game_iface_safe_act (void); -static void game_iface_gameover_act (void); - /* Actions: game */ -static void game_iface_act_game (void); - /* Actions: game_iface */ -static void game_iface_pause (void); -static void game_iface_unpause (void); -static void game_iface_xyzzy_on (void); -static void game_iface_xyzzy_off (void); -static void game_iface_save_score (void); -static void game_iface_quit (void); - /* Output */ -static void game_iface_update_out (void); -static void game_iface_update_board (void); -static void game_iface_update_vis (int r, int c); -static void game_iface_update_usr (int r, int c); - /* Score */ -static void game_iface_update_score (void); - /* Prepare input */ -static void game_iface_clean_in (void); - - -/****************************************************************************** - ******* 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); - - game_iface_out.state = GAME_IFACE_STATE_PLAYING; - game_iface_init_score(level); - - game_iface_out.rows = game_board.rows; - game_iface_out.cols = game_board.cols; - game_iface_out.mines = game_board.mines; - game_iface_update_out(); - game_iface_update_score(); - game_iface_clean_in(); -} - -void game_iface_init_load (void) -{ - - game_iface_init_cheated(); - - game_iface_out.rows = game_board.rows; - game_iface_out.cols = game_board.cols; - game_iface_out.mines = game_board.mines; - game_iface_update_out(); - game_iface_clean_in(); -} - -void game_iface (void) -{ - - while (game_iface_out.state != GAME_IFACE_STATE_QUIT) { - game_iface_update_out(); - game_iface_update_score(); - game_iface_clean_in(); - - player_iface(&game_iface_out, &game_iface_score, &game_iface_in); - - game_iface_act(); - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Init * * * * * * * - * * * * * * * * * */ -static void game_iface_init_score (int level) -{ - - game_iface_score.level = level; - tim_ini = time(NULL); - game_iface_score.clicks = 1; -} - -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; -} - -/* * * * * * * * * * - * * * Actions * * * * * * - * * * * * * * * * */ -static void game_iface_act (void) -{ - - switch (game_iface_out.state) { - case GAME_IFACE_STATE_PLAYING: - game_iface_playing_act(); - break; - case GAME_IFACE_STATE_CHEATED: - game_iface_cheated_act(); - break; - case GAME_IFACE_STATE_XYZZY: - game_iface_xyzzy_act(); - break; - case GAME_IFACE_STATE_PAUSE: - game_iface_pause_act(); - break; - case GAME_IFACE_STATE_SAFE: - game_iface_safe_act(); - break; - case GAME_IFACE_STATE_GAMEOVER: - game_iface_gameover_act(); - break; - } -} - -static void game_iface_playing_act (void) -{ - - switch (game_iface_in.action) { - case GAME_IFACE_ACT_PLAY: - game_iface_act_game(); - break; - case GAME_IFACE_ACT_PAUSE: - game_iface_pause(); - 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; - } -} - -static void game_iface_xyzzy_act (void) -{ - bool wh; - - xyzzy_init(); - - wh = true; - while (wh) { - switch (game_iface_in.action) { - case GAME_IFACE_ACT_PLAY: - 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; - } - } -} - -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; - } -} - -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; - } -} - -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; - } -} - -static void game_iface_gameover_act (void) -{ - - switch (game_iface_in.action) { - case GAME_IFACE_ACT_QUIT: - game_iface_quit(); - break; - } -} - -/* * * * * * * * * * - * * * Actions: game * * * * * - * * * * * * * * * */ -static void game_iface_act_game (void) -{ - int i; - int j; - - for (i = 0; i < game_board.rows; i++) { - for (j = 0; j < game_board.cols; j++) { - if (game_iface_in.act_game[i][j]) { - game_action(game_iface_in.act_game[i][j], i, j); - game_iface_score.clicks++; - } - } - } -} - -/* * * * * * * * * * - * * * Actions: game_iface * * * * * - * * * * * * * * * */ -static void game_iface_pause (void) -{ - time_t tim_now; - - tim_now = time(NULL); - game_iface_score.time = (int)(tim_now - tim_ini); - game_iface_out.state = GAME_IFACE_STATE_PAUSE; -} - -static void game_iface_unpause (void) -{ - time_t tim_now; - - tim_now = time(NULL); - tim_ini = tim_now - (time_t)game_iface_score.time; - game_iface_out.state = GAME_IFACE_STATE_PLAYING; -} - -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; - } -} - -static void game_iface_quit (void) -{ - - game_iface_out.state = GAME_IFACE_STATE_QUIT; -} - -/* * * * * * * * * * - * * * Output * * * * * * - * * * * * * * * * */ -static void game_iface_update_out (void) -{ - - game_iface_out.flags = game_board.flags; - game_iface_out.clr = game_board.clr; - - switch (game_board.state) { - 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; - } - - game_iface_update_board(); -} - -static void game_iface_update_board (void) -{ - int i; - int j; - - for (i = 0; i < game_board.rows; i++) { - for (j = 0; j < game_board.cols; j++) { - game_iface_update_vis(i, j); - game_iface_update_usr(i, j); - } - } -} - -static void game_iface_update_vis (int r, int c) -{ - int field_vis; - - switch (game_iface_out.state) { - case GAME_IFACE_STATE_CHEATED: - case GAME_IFACE_STATE_XYZZY: - case GAME_IFACE_STATE_PLAYING: - switch (game_board.usr[r][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; - - 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; - else - 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; - else - 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; - else - field_vis = GAME_IFACE_VIS_POSSIBLE_FALSE; - break; - } - break; - default: - field_vis = GAME_IFACE_VIS_HIDDEN_FIELD; - break; - } - - game_iface_out.visible[r][c] = field_vis; -} - -static void game_iface_update_usr (int r, int c) -{ - int field_usr; - - switch (game_board.usr[r][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; - } - - game_iface_out.usr[r][c] = field_usr; -} - -/* * * * * * * * * * - * * * Score * * * * * * * - * * * * * * * * * */ -static void game_iface_update_score (void) -{ - time_t tim_now; - - switch (game_iface_out.state) { - case GAME_IFACE_STATE_PLAYING: - 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; - game_iface_score.time = CHEATED; - game_iface_score.clicks = CHEATED; - break; - } -} - -/* * * * * * * * * * - * * * Prepare input * * * * * * - * * * * * * * * * */ -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; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/game/tmp/Makefile b/modules/game/tmp/Makefile deleted file mode 100644 index 9cea18b..0000000 --- a/modules/game/tmp/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -PLAY_INC_DIR = $(PLAY_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -XYZZY_INC_DIR = $(XYZZY_DIR)/inc/ - -INC_DIR = $(GAME_DIR)/inc/ -SRC_DIR = $(GAME_DIR)/src/ - -# dependencies - -_ALL = game.o game_iface.o -ALL = $(_ALL) game_mod.o - -GAME_INC_LIBALX = libalx/alx_seed.h -GAME_INC_SAVE = save.h -GAME_INC = game.h -GAME_DEPS = $(SRC_DIR)/game.c \ - $(patsubst %,$(INC_DIR)/%,$(GAME_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(GAME_INC_LIBALX)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(GAME_INC_SAVE)) -GAME_INC_DIRS = -I $(INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -GAMEI_INC_PLAY = player_iface.h -GAMEI_INC_SAVE = save.h score.h -GAMEI_INC_XYZZY = xyzzy.h -GAMEI_INC = game_iface.h game.h -GAMEI_DEPS = $(SRC_DIR)/game_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(GAME_INC)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(GAMEI_INC_PLAY)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(GAME_INC_SAVE)) \ - $(patsubst %,$(XYZZY_INC_DIR)/%,$(GAMEI_INC_XYZZY)) -GAMEI_INC_DIRS = -I $(INC_DIR) \ - -I $(PLAY_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(XYZZY_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -game_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -game.s: $(GAME_DEPS) - $(Q)$(CC) $(CFLAGS) $(GAME_INC_DIRS) -S $< -o $@ - @echo " CC $@" -game.o: game.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -game_iface.s: $(GAMEI_DEPS) - $(Q)$(CC) $(CFLAGS) $(GAMEI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -game_iface.o: game_iface.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/menu/Makefile b/modules/menu/Makefile deleted file mode 100644 index 48ed965..0000000 --- a/modules/menu/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(MENU_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h deleted file mode 100644 index 69060a5..0000000 --- a/modules/menu/inc/menu_clui.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * 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_gui.h b/modules/menu/inc/menu_gui.h deleted file mode 100644 index 4269cdc..0000000 --- a/modules/menu/inc/menu_gui.h +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_MENU_GUI_H - # define MSW_MENU_GUI_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* GtkWidget */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ROWS_GUI_MAX (22) -#if (ROWS_GUI_MAX > ROWS_MAX) -# error "rows max (gui)" -#endif - - # define COLS_GUI_MAX (33) -#if (COLS_GUI_MAX > COLS_MAX) -# error "cols max (gui)" -#endif - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern GtkWidget *window_gui; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_gui_init (void); - void menu_gui_cleanup (void); - void menu_gui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_gui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h deleted file mode 100644 index 83eeead..0000000 --- a/modules/menu/inc/menu_iface.h +++ /dev/null @@ -1,67 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_MENU_IFACE_H - # define MSW_MENU_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI, - MENU_IFACE_GUI - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Menu_Iface_Variables { - int level; - int rows; - int cols; - double p; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern bool flag_exit; -extern int menu_iface_mode; -extern struct Menu_Iface_Variables menu_iface_variables; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface_init (void); -void menu_iface_init_iface (void); -void menu_iface_cleanup (void); -void menu_iface_board (int *level, int *rows, int *cols, int *mines); -void menu_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h deleted file mode 100644 index 71e3104..0000000 --- a/modules/menu/inc/menu_tui.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_MENU_TUI_H - # define MSW_MENU_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_tui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h deleted file mode 100644 index 38fac23..0000000 --- a/modules/menu/inc/parser.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_PARSER_H - # define MSW_PARSER_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c deleted file mode 100644 index d3f8d8b..0000000 --- a/modules/menu/src/menu_clui.c +++ /dev/null @@ -1,240 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - - #include "libalx/io/alx_input.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 (26) -#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 c; - - c = 'n'; - printf("Read 'Disclaimer of warranty'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'y' || c == 'Y') { - printf(" >yes\n"); - print_share_file(SHARE_DISCLAIMER); - } else { - printf(" >NO\n"); - } - - c = 'n'; - printf("Read 'License'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'y' || c == 'Y') { - printf(" >yes\n"); - print_share_file(SHARE_LICENSE); - } else { - printf(" >NO\n"); - } -#if 0 - printf("Game interface? (NCURSES/text): "); - scanf(" %c%*s ", &c); - if (c == 't' || c == 'T') { - printf(" >text\n"); - // FIXME - } else { - printf(" >NCURSES\n"); - // FIXME - } -#endif - c = 'n'; - printf("New game or load game? (NEW/load): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'l' || c == 'L') { - printf(" >load\n"); - menu_clui_load(); - } else { - printf(" >NEW\n"); - menu_clui_rand(); - } - - return; - - -err_fgets: - printf("fgets() error\n"); - exit(EXIT_FAILURE); -err_sscanf: - printf("sscanf() error\n"); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_clui_rand (void) -{ - int seed; - char buff [BUFF_SIZE]; - char c; - - /* Random */ - start_mode = START_RAND; - - c = 'n'; - printf("Set seed for random generator? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'y' || c == 'Y') { - printf(" >yes\n"); - seed = alx_getint(-INFINITY, 1, INFINITY, "Seed:", NULL); - srand(seed); - } else { - printf(" >NO\n"); - } - - c = 'b'; - printf("Level? (BEGINNER/intermediate/(expert)/custom): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'i' || c == 'I') { - printf(" >intermediate\n"); - menu_iface_variables.level = GAME_IFACE_LEVEL_INTERMEDIATE; - menu_clui_start(); - } else if (c == 'e' || c == 'E') { - printf(" >expert\n"); - menu_iface_variables.level = GAME_IFACE_LEVEL_EXPERT_INV; - menu_clui_start(); - } else if (c == 'c' || c == 'C') { - printf(" >custom\n"); - menu_iface_variables.level = GAME_IFACE_LEVEL_CUSTOM; - menu_clui_custom(); - } else { - printf(" >BEGINNER\n"); - menu_iface_variables.level = GAME_IFACE_LEVEL_BEGINNER; - menu_clui_start(); - } - - return; - - -err_fgets: - printf("fgets() error\n"); - exit(EXIT_FAILURE); -err_sscanf: - printf("sscanf() error\n"); - exit(EXIT_FAILURE); -} - -static void menu_clui_custom (void) -{ - - 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) -{ - - 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) -{ - char buff [BUFF_SIZE]; - char c; - - printf(" >>START:\n"); - start_switch(); - - c = 'm'; - printf("Play again? (MENU/play/exit): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %c", &c) != 1) - goto err_sscanf; - if (c == 'p' || c == 'P') { - printf(" >play\n"); - menu_clui_start(); - } else if (c == 'e' || c == 'E') { - printf(" >exit!\n"); - } else { - printf(" >MENU\n"); - menu_clui(); - } - - return; - - -err_fgets: - printf("fgets() error\n"); - exit(EXIT_FAILURE); -err_sscanf: - printf("sscanf() error\n"); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_gui.c b/modules/menu/src/menu_gui.c deleted file mode 100644 index 607ec30..0000000 --- a/modules/menu/src/menu_gui.c +++ /dev/null @@ -1,991 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - #include - #include - #include - - #include "libalx/io/alx_input.h" - - #include "about.h" - #include "game_iface.h" - #include "save.h" - #include "score.h" - #include "start.h" - #include "menu_iface.h" - - #include "menu_gui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LINE_SIZE (80) - # define BUFF_SIZE_TEXT (1048576) - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Button_Data { - GtkWidget *ptr; - char text [LINE_SIZE]; - int num; - int *sw; -}; - -struct Label_Data { - GtkWidget *ptr; - char text [LINE_SIZE]; -}; - -struct Entry_dbl_Data { - GtkWidget *ptr; - struct Label_Data lbl; - double *num; - double min; - double def; - double max; -}; - -struct Entry_int_Data { - GtkWidget *ptr; - struct Label_Data lbl; - int *num; - double min; - int64_t def; - double max; -}; - -struct Entry_fname_Data { - GtkWidget *ptr; - struct Label_Data lbl; - const char *fpath; - char *fname; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* * * * * * * * * * - * * * Global * * * * * * - * * * * * * * * * */ - GtkWidget *window_gui; - -/* * * * * * * * * * - * * * Static * * * * * * - * * * * * * * * * */ -static GtkWidget *box; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Init & cleanup */ -static gboolean delete_window (GtkWidget *widget, - GdkEvent *event, - void *data); -static void destroy_window (GtkWidget *widget, - void *data); - /* Selection */ -static void callback_button (GtkWidget *widget, - void *data); - /* Entries */ -static void callback_entry_dbl (GtkWidget *widget, - void *data); -static void callback_entry_int (GtkWidget *widget, - void *data); - /* Text */ -static void menu_gui_disclaim (void); -static void menu_gui_license (void); -static void menu_gui_hiscores (void); - /* Submenus */ -static void menu_gui_continue (void); -static void menu_gui_select (void); -static void menu_gui_level (void); -static void menu_gui_custom (void); -static void menu_gui_devel (void); -#if 0 -static void menu_gui_verbose (void); -#endif - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_gui_init (void) -{ - char title [LINE_SIZE]; - - window_gui = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - g_signal_connect(window_gui, "delete-event", G_CALLBACK(delete_window), NULL); - g_signal_connect(window_gui, "destroy", G_CALLBACK(destroy_window), NULL); - - /* Title. PROG_VERSION defined in Makefile */ - (void)snprintf(title, LINE_SIZE, "mine-sweeper %s", PROG_VERSION); - gtk_window_set_title(GTK_WINDOW(window_gui), title); - gtk_container_set_border_width(GTK_CONTAINER(window_gui), 20); -} - -void menu_gui_cleanup (void) -{ - - gtk_widget_destroy(window_gui); -} - -void menu_gui (void) -{ - bool wh; - int sw; - GtkWidget *separator[3]; - struct Label_Data label; - struct Button_Data button [4]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Main menu"); - (void)snprintf(button[1].text, LINE_SIZE, "[_1] Continue"); - (void)snprintf(button[2].text, LINE_SIZE, "[_2] Disclaimer of warranty"); - (void)snprintf(button[3].text, LINE_SIZE, "[_3] Terms and conditions"); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Exit program"); - - /* Data */ - button[1].num = 1; - button[2].num = 2; - button[3].num = 3; - button[0].num = 0; - button[1].sw = &sw; - button[2].sw = &sw; - button[3].sw = &sw; - button[0].sw = &sw; - - /* Menu loop */ - wh = true; - while (wh) { - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - button[1].ptr = gtk_button_new_with_mnemonic(button[1].text); - separator[1] = gtk_hseparator_new(); - button[2].ptr = gtk_button_new_with_mnemonic(button[2].text); - button[3].ptr = gtk_button_new_with_mnemonic(button[3].text); - separator[2] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[1].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[1]); - g_signal_connect(button[2].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[2]); - g_signal_connect(button[3].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[3]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - case 1: - menu_gui_continue(); - break; - case 2: - menu_gui_disclaim(); - break; - case 3: - menu_gui_license(); - break; - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * Cleanup * * * * * * - * * * * * * * * * */ -static gboolean delete_window (GtkWidget *widget, - GdkEvent *event, - void *data) -{ - - gtk_main_quit(); - - /* false: send destroy signal */ - return false; -} - -static void destroy_window (GtkWidget *widget, - void *data) -{ - - exit(EXIT_SUCCESS); -} - -/* * * * * * * * * * - * * Selection * * * * * * - * * * * * * * * * */ -static void callback_button (GtkWidget *widget, - void *data) -{ - struct Button_Data *button; - - button = ((struct Button_Data *)data); - - *(button->sw) = button->num; - - gtk_main_quit(); -} - -/* * * * * * * * * * - * * Entries * * * * * * * - * * * * * * * * * */ -static void callback_entry_dbl (GtkWidget *widget, - void *data) -{ - struct Entry_dbl_Data *entry; - const char *str; - char buff [LINE_SIZE]; - - entry = ((struct Entry_dbl_Data *)data); - - str = gtk_entry_get_text(GTK_ENTRY(entry->ptr)); - if (alx_sscan_dbl(entry->num, entry->min, entry->def, entry->max, str)) - goto err; - - gtk_main_quit(); - return; - -err: - (void)snprintf(buff, LINE_SIZE, "Error in alx_sscan_dbl()"); - gtk_entry_set_text(GTK_ENTRY(entry->ptr), buff); - gtk_editable_select_region(GTK_EDITABLE(entry->ptr), - 0, GTK_ENTRY(entry->ptr)->text_length); - gtk_main_quit(); -} - -static void callback_entry_int (GtkWidget *widget, - void *data) -{ - struct Entry_int_Data *entry; - const char *str; - int64_t Z; - char buff [LINE_SIZE]; - - entry = ((struct Entry_int_Data *)data); - - str = gtk_entry_get_text(GTK_ENTRY(entry->ptr)); - if (alx_sscan_i64(&Z, entry->min, entry->def, entry->max, str)) - goto err; - *(entry->num) = Z; - - gtk_main_quit(); - return; - -err: - (void)snprintf(buff, LINE_SIZE, "Error in alx_sscan_i64()"); - gtk_entry_set_text(GTK_ENTRY(entry->ptr), buff); - gtk_editable_select_region(GTK_EDITABLE(entry->ptr), - 0, GTK_ENTRY(entry->ptr)->text_length); - gtk_main_quit(); -} - -static void callback_entry_fname (GtkWidget *widget, - void *data) -{ - struct Entry_fname_Data *entry; - const char *str; - char buff [LINE_SIZE]; - - entry = ((struct Entry_fname_Data *)data); - - str = gtk_entry_get_text(GTK_ENTRY(entry->ptr)); - if (alx_sscan_fname(entry->fpath, entry->fname, true, str)) - goto err; - - gtk_main_quit(); - return; - -err: - (void)snprintf(buff, LINE_SIZE, "Error in alx_sscan_fname()"); - gtk_entry_set_text(GTK_ENTRY(entry->ptr), buff); - gtk_editable_select_region(GTK_EDITABLE(entry->ptr), - 0, GTK_ENTRY(entry->ptr)->text_length); - gtk_main_quit(); -} - -/* * * * * * * * * * - * * Text * * * * * * * - * * * * * * * * * */ -static void menu_gui_disclaim (void) -{ - int sw; - GtkWidget *separator[2]; - struct Label_Data label; - struct Button_Data button [1]; - GtkWidget *label_file; - char label_file_txt [BUFF_SIZE_TEXT]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Disclaimer of warranty"); - snprint_share_file(label_file_txt, BUFF_SIZE_TEXT, SHARE_DISCLAIMER); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[0].num = 0; - button[0].sw = &sw; - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - label_file = gtk_label_new(label_file_txt); - separator[1] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), label_file, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); -} - -static void menu_gui_license (void) -{ - int sw; - GtkWidget *separator[2]; - struct Label_Data label; - struct Button_Data button [1]; - GtkWidget *label_file; - char label_file_txt [BUFF_SIZE_TEXT]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Terms and conditions"); - snprint_share_file(label_file_txt, BUFF_SIZE_TEXT, SHARE_LICENSE); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[0].num = 0; - button[0].sw = &sw; - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - label_file = gtk_label_new(label_file_txt); - separator[1] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), label_file, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); -} - -static void menu_gui_hiscores (void) -{ - int sw; - GtkWidget *separator[2]; - struct Label_Data label; - struct Button_Data button [1]; - GtkWidget *label_file; - char label_file_txt [BUFF_SIZE_TEXT]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Hi scores"); - snprint_scores(label_file_txt, BUFF_SIZE_TEXT); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[0].num = 0; - button[0].sw = &sw; - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - label_file = gtk_label_new(label_file_txt); - separator[1] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), label_file, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); -} - -/* * * * * * * * * * - * * Submenus * * * * * * - * * * * * * * * * */ -static void menu_gui_continue (void) -{ - bool wh; - int sw; - GtkWidget *separator[4]; - struct Label_Data label; - struct Button_Data button [6]; - struct Entry_fname_Data entry_fname[1]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Game menu"); - (void)snprintf(button[1].text, LINE_SIZE, "[_1] Start"); - (void)snprintf(button[2].text, LINE_SIZE, "[_2] Select map"); - (void)snprintf(button[3].text, LINE_SIZE, "[_3] Change difficulty"); - (void)snprintf(button[4].text, LINE_SIZE, "[_4] Hi scores"); - (void)snprintf(button[5].text, LINE_SIZE, "[_5] DEVEL"); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[1].num = 1; - button[2].num = 2; - button[3].num = 3; - button[4].num = 4; - button[5].num = 5; - button[0].num = 0; - button[1].sw = &sw; - button[2].sw = &sw; - button[3].sw = &sw; - entry_fname[0].fpath = saved_path; - entry_fname[0].fname = saved_name; - button[4].sw = &sw; - button[5].sw = &sw; - button[0].sw = &sw; - - /* Menu loop */ - wh = true; - while (wh) { - /* Text */ - (void)snprintf(entry_fname[0].lbl.text, LINE_SIZE, - "Change file name (File: \"%s\")", saved_name); - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - button[1].ptr = gtk_button_new_with_mnemonic(button[1].text); - separator[1] = gtk_hseparator_new(); - button[2].ptr = gtk_button_new_with_mnemonic(button[2].text); - button[3].ptr = gtk_button_new_with_mnemonic(button[3].text); - entry_fname[0].lbl.ptr = gtk_label_new(entry_fname[0].lbl.text); - entry_fname[0].ptr = gtk_entry_new(); - button[4].ptr = gtk_button_new_with_mnemonic(button[4].text); - separator[2] = gtk_hseparator_new(); - button[5].ptr = gtk_button_new_with_mnemonic(button[5].text); - separator[3] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[1].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[1]); - g_signal_connect(button[2].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[2]); - g_signal_connect(button[3].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[3]); - g_signal_connect(entry_fname[0].ptr, "activate", - G_CALLBACK(callback_entry_fname), (void *)&entry_fname[0]); - g_signal_connect(button[4].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[4]); - g_signal_connect(button[5].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[5]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_fname[0].lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_fname[0].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), button[4].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[5].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[3], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - case 1: - start_switch(); - break; - case 2: - menu_gui_select(); - break; - case 3: - menu_gui_level(); - break; - case 4: - menu_gui_hiscores(); - break; - case 5: - menu_gui_devel(); - break; - } - } -} - -static void menu_gui_select (void) -{ - int sw; - GtkWidget *separator[3]; - struct Label_Data label; - struct Button_Data button [3]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Select map"); - (void)snprintf(button[1].text, LINE_SIZE, "[_1] New map"); - (void)snprintf(button[2].text, LINE_SIZE, "[_2] Load map (File: \"%s\")", - saved_name); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[1].num = 1; - button[2].num = 2; - button[0].num = 0; - button[1].sw = &sw; - button[2].sw = &sw; - button[0].sw = &sw; - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - button[1].ptr = gtk_button_new_with_mnemonic(button[1].text); - separator[1] = gtk_hseparator_new(); - button[2].ptr = gtk_button_new_with_mnemonic(button[2].text); - separator[2] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[1].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[1]); - g_signal_connect(button[2].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[2]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); - - /* Selection */ - switch (sw) { - case 0: - break; - case 1: - start_mode = START_RAND; - break; - case 2: - start_mode = START_LOAD; - break; - } -} - -static void menu_gui_level (void) -{ - int sw; - GtkWidget *separator[3]; - struct Label_Data label; - struct Button_Data button [5]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Select level"); - (void)snprintf(button[1].text, LINE_SIZE, "[_1] Beginner"); - (void)snprintf(button[2].text, LINE_SIZE, "[_2] Intermediate"); - (void)snprintf(button[3].text, LINE_SIZE, "[_3] Expert"); - (void)snprintf(button[4].text, LINE_SIZE, "[_4] Custom"); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - button[1].num = 1; - button[2].num = 2; - button[3].num = 3; - button[4].num = 4; - button[0].num = 0; - button[1].sw = &sw; - button[2].sw = &sw; - button[3].sw = &sw; - button[4].sw = &sw; - button[0].sw = &sw; - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - button[1].ptr = gtk_button_new_with_mnemonic(button[1].text); - button[2].ptr = gtk_button_new_with_mnemonic(button[2].text); - button[3].ptr = gtk_button_new_with_mnemonic(button[3].text); - separator[1] = gtk_hseparator_new(); - button[4].ptr = gtk_button_new_with_mnemonic(button[4].text); - separator[2] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(button[1].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[1]); - g_signal_connect(button[2].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[2]); - g_signal_connect(button[3].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[3]); - g_signal_connect(button[4].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[4]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[1].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), button[2].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), button[3].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[4].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Clear window */ - gtk_widget_destroy(box); - - /* 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_gui_custom(); - break; - } -} - -static void menu_gui_custom (void) -{ - bool wh; - int sw; - GtkWidget *separator[3]; - struct Label_Data label; - struct Button_Data button [1]; - struct Entry_int_Data entry_int[2]; - struct Entry_dbl_Data entry_dbl[1]; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "Custom"); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - entry_int[0].num = &menu_iface_variables.rows; - entry_int[0].min = 2; - entry_int[0].def = menu_iface_variables.rows; - entry_int[0].max = ROWS_GUI_MAX; - entry_int[1].num = &menu_iface_variables.cols; - entry_int[1].min = 2; - entry_int[1].def = menu_iface_variables.cols; - entry_int[1].max = COLS_GUI_MAX; - entry_dbl[0].num = &menu_iface_variables.p; - entry_dbl[0].min = 0; - entry_dbl[0].def = menu_iface_variables.p; - entry_dbl[0].max = 1; - button[0].num = 0; - button[0].sw = &sw; - - /* Menu loop */ - wh = true; - while (wh) { - - /* Text */ - (void)snprintf(entry_int[0].lbl.text, LINE_SIZE, - "Change rows: rows\t\t(%i)\n" - "Introduce an integer number [%i U %i]", - menu_iface_variables.rows, 2, ROWS_GUI_MAX); - (void)snprintf(entry_int[1].lbl.text, LINE_SIZE, - "Change columns: cols\t(%i)\n" - "Introduce an integer number [%i U %i]", - menu_iface_variables.cols, 2, COLS_GUI_MAX); - (void)snprintf(entry_dbl[0].lbl.text, LINE_SIZE, - "Change proportion of mines: p\t(%lf)\n" - "Introduce a Real number [%i U %i]", - menu_iface_variables.p, 0, 1); - - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - entry_int[0].lbl.ptr = gtk_label_new(entry_int[0].lbl.text); - entry_int[0].ptr = gtk_entry_new(); - entry_int[1].lbl.ptr = gtk_label_new(entry_int[1].lbl.text); - entry_int[1].ptr = gtk_entry_new(); - separator[1] = gtk_hseparator_new(); - entry_dbl[0].lbl.ptr = gtk_label_new(entry_dbl[0].lbl.text); - entry_dbl[0].ptr = gtk_entry_new(); - separator[2] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(entry_int[0].ptr, "activate", - G_CALLBACK(callback_entry_int), (void *)&entry_int[0]); - g_signal_connect(entry_int[1].ptr, "activate", - G_CALLBACK(callback_entry_int), (void *)&entry_int[1]); - g_signal_connect(entry_dbl[0].ptr, "activate", - G_CALLBACK(callback_entry_dbl), (void *)&entry_dbl[0]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), entry_int[0].lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_int[0].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_int[1].lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_int[1].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), entry_dbl[0].lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_dbl[0].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[2], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - default: - break; - } - - /* Clear window */ - gtk_widget_destroy(box); - } -} - -static void menu_gui_devel (void) -{ - bool wh; - int sw; - GtkWidget *separator[2]; - struct Label_Data label; - struct Button_Data button [1]; - struct Entry_int_Data entry_int[1]; - int seed; - - /* Text */ - (void)snprintf(label.text, LINE_SIZE, "DEVELOPER OPTIONS"); - (void)snprintf(entry_int[0].lbl.text, LINE_SIZE, "Change seed (srand)"); - (void)snprintf(button[0].text, LINE_SIZE, "[_0] Back"); - - /* Data */ - entry_int[0].num = &seed; - entry_int[0].min = -INFINITY; - entry_int[0].def = 1; - entry_int[0].max = INFINITY; - button[0].num = 0; - button[0].sw = &sw; - - /* Text */ - - /* Menu loop */ - wh = true; - while (wh) { - /* Generate widgets */ - box = gtk_vbox_new(false, 0); - label.ptr = gtk_label_new(label.text); - separator[0] = gtk_hseparator_new(); - entry_int[0].lbl.ptr = gtk_label_new(entry_int[0].lbl.text); - entry_int[0].ptr = gtk_entry_new(); - separator[1] = gtk_hseparator_new(); - button[0].ptr = gtk_button_new_with_mnemonic(button[0].text); - - /* Events */ - g_signal_connect(entry_int[0].ptr, "activate", - G_CALLBACK(callback_entry_int), (void *)&entry_int[0]); - g_signal_connect(button[0].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[0]); - - /* Container */ - gtk_container_add(GTK_CONTAINER(window_gui), box); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box), label.ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box), separator[0], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), entry_int[0].lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), entry_int[0].ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box), separator[1], false, false, 5); - gtk_box_pack_start(GTK_BOX(box), button[0].ptr, true, true, 0); - - /* Refresh */ - gtk_widget_show_all(window_gui); - - /* GTK loop */ - sw = -1; - gtk_main(); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - default: - srand(seed); - break; - } - - /* Clear window */ - gtk_widget_destroy(box); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c deleted file mode 100644 index 3927ca7..0000000 --- a/modules/menu/src/menu_iface.c +++ /dev/null @@ -1,133 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - - #include "game_iface.h" - #include "start.h" - #include "menu_clui.h" - #include "menu_tui.h" - #include "menu_gui.h" - - #include "menu_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -bool flag_exit; -int menu_iface_mode; -struct Menu_Iface_Variables menu_iface_variables; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -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_init_iface (void) -{ - - switch (menu_iface_mode) { - case MENU_IFACE_CLUI: - break; - case MENU_IFACE_TUI: - break; - case MENU_IFACE_GUI: - menu_gui_init(); - break; - } -} - -void menu_iface_cleanup (void) -{ - - switch (menu_iface_mode) { - case MENU_IFACE_CLUI: - break; - case MENU_IFACE_TUI: - break; - case MENU_IFACE_GUI: - menu_gui_cleanup(); - break; - } -} - -void menu_iface_board (int *level, int *rows, int *cols, int *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_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; - *mines = menu_iface_variables.p * (*rows) * (*cols); - /* at least one safe field */ - if ((*mines) == (*rows) * (*cols)) - (*mines)--; - break; - } -} - -void menu_iface (void) -{ - - start_mode = START_RAND; - - if (flag_exit) - return; - - switch (menu_iface_mode) { - case MENU_IFACE_FOO: - break; - case MENU_IFACE_CLUI: - menu_clui(); - break; - case MENU_IFACE_TUI: - menu_tui(); - break; - case MENU_IFACE_GUI: - menu_gui(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c deleted file mode 100644 index a39caea..0000000 --- a/modules/menu/src/menu_tui.c +++ /dev/null @@ -1,423 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - #include - #include - - #include "libalx/curses/alx_ncur.h" - - #include "about.h" - #include "game_iface.h" - #include "save.h" - #include "score.h" - #include "start.h" - #include "menu_iface.h" - - #include "menu_tui.h" - - -/****************************************************************************** - ******* 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 - -#define BUFF_SIZE_TEXT (1048576) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void); -static void menu_tui_select (void); -static void menu_tui_level (void); -static void menu_tui_custom (void); -#if 0 -static void menu_tui_devel (void); -#endif -#if 0 -static void menu_tui_verbose (void); -#endif - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_tui (void) -{ - int h; - int w; - int N; - bool wh; - int sw; - - alx_resume_curses(); - - /* Menu dimensions & options */ - h = 10; - w = 34; - N = 4; - static const struct Alx_Menu mnu[4] = { - {7, 4, "[0] Exit program"}, - {2, 4, "[1] Continue"}, - {4, 4, "[2] Disclaimer of warranty"}, - {5, 4, "[3] Terms and conditions"} - }; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "MENU:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - case 1: - menu_tui_continue(); - break; - case 2: - alx_pause_curses(); - print_share_file(SHARE_DISCLAIMER); - getchar(); - alx_resume_curses(); - break; - case 3: - alx_pause_curses(); - print_share_file(SHARE_LICENSE); - getchar(); - alx_resume_curses(); - break; - } - } - - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void) -{ - char str [BUFF_SIZE_TEXT]; - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - /* Menu dimensions & options */ - h = 18; - w = 50; - r = 1; - c = (80 - w) / 2; - /* N = 7 if DEVEL option is enabled */ - N = 6; - static const struct Alx_Menu mnu[6] = { - {11, 4, "[0] Back"}, - {2, 4, "[1] Start"}, - {4, 4, "[2] Select map"}, - {5, 4, "[3] Change difficulty"}, - {6, 4, "[4] Change file name"}, - {7, 4, "[5] Hi scores"}/*, - {9, 4, "[6] DEVEL"}*/ - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = {"File name:"}; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[4].r, mnu[4].c, "%s (File: \"%s\")", mnu[4].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "CONTINUE:"); - - /* Selection */ - switch (sw) { - case 0: - alx_win_del(win); - wh = false; - break; - case 1: - alx_win_del(win); - alx_pause_curses(); - start_switch(); - alx_resume_curses(); - break; - case 2: - alx_win_del(win); - menu_tui_select(); - break; - case 3: - alx_win_del(win); - menu_tui_level(); - break; - case 4: - save_clr(); - alx_w_getfname(saved_path, saved_name, true, w2, r2, - txt[0], NULL); - alx_win_del(win); - break; - case 5: - alx_win_del(win); - alx_pause_curses(); - snprint_scores(str, BUFF_SIZE_TEXT); - printf("%s", str); - getchar(); - alx_resume_curses(); - break; -/* - case 6: - alx_win_del(win); - menu_tui_devel(); - break; -*/ - } - } -} - -static void menu_tui_select (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int sw; - - /* Menu dimensions & options */ - h = 9; - w = 70; - r = 1; - c = (80 - w) / 2; - N = 3; - static const struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] New map"}, - {4, 4, "[2] Load map"} - }; - - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[2].r, mnu[2].c, "%s (File: \"%s\")", mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "SELECT MAP:"); - alx_win_del(win); - - /* Selection */ - switch (sw) { - case 1: - start_mode = START_RAND; - break; - case 2: - start_mode = START_LOAD; - break; - } - -} - -static void menu_tui_level (void) -{ - int h; - int w; - int N; - int sw; - - /* Menu dimensions & options */ - h = 10; - w = 70; - N = 5; - static const struct Alx_Menu mnu[5] = { - {7, 4, "[0] Back"}, - {2, 4, "[1] Beginner"}, - {3, 4, "[2] Intermediate"}, - {4, 4, "[3] Expert"}, - {5, 4, "[4] Custom"} - }; - - /* Menu loop */ - 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) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - /* Menu dimensions & options */ - h = 16; - w = 76; - r = 1; - c = (80 - w) / 2; - N = 4; - static const struct Alx_Menu mnu[4] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Change rows:"}, - {4, 4, "[2] Change columns:"}, - {6, 4, "[3] Change proportion of mines:"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = { - "Rows:", - "Columns:", - "Proportion:" - }; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - wh = true; - while (wh) { - mvwprintw(win, mnu[1].r, mnu[1].c, "%s rows\t\t(%i)", - mnu[1].t, menu_iface_variables.rows); - mvwprintw(win, mnu[2].r, mnu[2].c, "%s cols\t\t(%i)", - mnu[2].t, menu_iface_variables.cols); - mvwprintw(win, mnu[3].r, mnu[3].c, "%s p\t(%lf)", - mnu[3].t, menu_iface_variables.p); - wrefresh(win); - - /* Selection */ - sw = alx_menu_2(win, N, mnu, "Custom:"); - - switch (sw) { - case 0: - wh = false; - break; - case 1: - menu_iface_variables.rows = alx_w_getint(w2, r2, - txt[sw - 1], 2, menu_iface_variables.rows, ROWS_TUI_MAX, NULL); - break; - case 2: - menu_iface_variables.cols = alx_w_getint(w2, r2, - txt[sw - 1], 2, menu_iface_variables.cols, COLS_TUI_MAX, NULL); - break; - case 3: - menu_iface_variables.p = alx_w_getdbl(w2, r2, - txt[sw - 1], 0, menu_iface_variables.p, 1, NULL); - break; - } - - } - - alx_win_del(win); -} -#if 0 -static void menu_tui_devel (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - int seed; - - h = 12; - w = 50; - r = 1; - c = (80 - w) / 2; - N = 2; - static const struct Alx_Menu mnu[2] = { - {5, 4, "[0] Back"}, - {2, 4, "[1] Change seed (srand)"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = {"Seed:"}; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - wh = true; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); - - switch (sw) { - case 0: - wh = false; - break; - case 1: - seed = alx_w_getint(w2, r2, txt[0], - -INFINITY, 1, INFINITY, NULL); - srand(seed); - break; - } - } - - alx_win_del(win); -} -#endif - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c deleted file mode 100644 index cff49e9..0000000 --- a/modules/menu/src/parser.c +++ /dev/null @@ -1,226 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include - #include -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_seed.h" -/* Project -------------------------------------------------------------------*/ - #include "about.h" - #include "game_iface.h" - #include "player_iface.h" - #include "save.h" - #include "start.h" - #include "menu_iface.h" - - #include "parser.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OPT_LIST "xhLuv""a:b:f:i:p:r:s:" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_rows (char *argument); -static void parse_columns (char *argument); -static void parse_file (char *argument); -static void parse_iface (char *argument); -static void parse_proportion (char *argument); -#if 0 -static void parse_rand_seed (char *argument); -#endif -static void parse_start (char *argument); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void parser (int argc, char *argv[]) -{ - int opt = 0; - int opt_index = 0; - - const struct option long_options[] = { - /* Standard */ - {"exit", no_argument, 0, 'x'}, - {"help", no_argument, 0, 'h'}, - {"license", no_argument, 0, 'L'}, - {"usage", no_argument, 0, 'u'}, - {"version", no_argument, 0, 'v'}, - /* Non-standard */ - {"rows", required_argument, 0, 'a'}, - {"columns", required_argument, 0, 'b'}, - {"file", required_argument, 0, 'f'}, - {"iface", required_argument, 0, 'i'}, - {"proportion", required_argument, 0, 'p'}, -// {"rand-seed", required_argument, 0, 'r'}, - {"start", required_argument, 0, 's'}, - /* Null */ - {0, 0, 0, 0} - }; - - while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, - &opt_index)) != -1) { - - switch (opt) { - /* Standard */ - 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); - - /* Non-standard */ - 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; -# if 0 -// for DEVEL - case 'r': - parse_rand_seed(optarg); - break; -# endif - case 's': - parse_start(optarg); - break; - case '?': - /* getopt_long already printed an error message. */ - default: - print_share_file(SHARE_USAGE); - exit(EXIT_FAILURE); - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -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"); - printf("It must be an integer [%i U %i]\n", 2, ROWS_MAX); - exit(EXIT_FAILURE); - } -} - -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"); - printf("It must be an integer [%i U %i]\n", 2, COLS_MAX); - exit(EXIT_FAILURE); - } -} - -static void parse_file (char *argument) -{ - FILE *fp; - - // FIXME - fp = fopen(argument, "r"); - if (!fp) - goto err_fp; - fclose(fp); - - saved_path[0] = '\0'; - snprintf(saved_name, FILENAME_MAX, argument); - - return; - -err_fp: - printf("--file argument not valid\n"); - printf("It must be a valid file name (relative to saved dir)\n"); - exit(EXIT_FAILURE); -} - -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)) { - printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", - MENU_IFACE_CLUI, MENU_IFACE_GUI); - exit(EXIT_FAILURE); - } -} - -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"); - printf("It must be a real [0 U 1]\n"); - exit(EXIT_FAILURE); - } -} -#if 0 -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"); - printf("It must be an integer [%i U %i]\n", - START_FOO, START_LOAD); - exit(EXIT_FAILURE); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile deleted file mode 100644 index ce766f4..0000000 --- a/modules/menu/tmp/Makefile +++ /dev/null @@ -1,165 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ -GAME_INC_DIR = $(GAME_DIR)/inc/ -PLAY_INC_DIR = $(PLAY_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ - -INC_DIR = $(MENU_DIR)/inc/ -SRC_DIR = $(MENU_DIR)/src/ - -# dependencies - -_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o menu_gui.o -ALL = $(_ALL) menu_mod.o - -PARS_INC_LIBALX = libalx/alx_seed.h -PARS_INC_ABOUT = about.h -PARS_INC_CTRL = start.h -PARS_INC_GAME = game_iface.h -PARS_INC_PLAY = player_iface.h -PARS_INC_SAVE = save.h -PARS_INC = parser.h menu_iface.h -PARS_DEPS = $(SRC_DIR)/parser.c \ - $(patsubst %,$(INC_DIR)/%,$(PARS_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PARS_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(PARS_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(PARS_INC_CTRL)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(PARS_INC_GAME)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(PARS_INC_PLAY)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(PARS_INC_SAVE)) -PARS_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(PLAY_INC_DIR) \ - -I $(SAVE_INC_DIR) - -MENUI_INC_CTRL = start.h -MENUI_INC_GAME = game_iface.h -MENUI_INC = menu_iface.h menu_clui.h menu_tui.h menu_gui.h -MENUI_DEPS = $(SRC_DIR)/menu_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUI_INC_CTRL)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(MENUI_INC_GAME)) -MENUI_INC_DIRS = -I $(INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(GAME_INC_DIR) - -MENUCLUI_INC_LIBALX = libalx/io/alx_input.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 = libalx/curses/alx_ncur.h -MENUTUI_INC_ABOUT = about.h -MENUTUI_INC_CTRL = start.h -MENUTUI_INC_GAME = game_iface.h -MENUTUI_INC_SAVE = save.h score.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) - -MENUGUI_INC_LIBALX = libalx/io/alx_input.h -MENUGUI_INC_ABOUT = about.h -MENUGUI_INC_CTRL = start.h -MENUGUI_INC_GAME = game_iface.h -MENUGUI_INC_SAVE = save.h score.h -MENUGUI_INC = menu_gui.h menu_iface.h -MENUGUI_DEPS = $(SRC_DIR)/menu_gui.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUGUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUGUI_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUGUI_INC_ABOUT)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(MENUGUI_INC_GAME)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUGUI_INC_CTRL)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUGUI_INC_SAVE)) -MENUGUI_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 -# action - -all: $(ALL) - - -menu_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -parser.s: $(PARS_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(PARS_INC_DIRS) -S $< -o $@ -parser.o: parser.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -menu_iface.s: $(MENUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(MENUI_INC_DIRS) -S $< -o $@ -menu_iface.o: menu_iface.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -menu_clui.s: $(MENUCLUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(MENUCLUI_INC_DIRS) -S $< -o $@ -menu_clui.o: menu_clui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -menu_tui.s: $(MENUTUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(MENUTUI_INC_DIRS) -S $< -o $@ -menu_tui.o: menu_tui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -menu_gui.s: $(MENUGUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(MENUGUI_INC_DIRS) -S $< -o $@ -menu_gui.o: menu_gui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/player/Makefile b/modules/player/Makefile deleted file mode 100644 index bbf6245..0000000 --- a/modules/player/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(PLAY_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/player/inc/player_clui.h b/modules/player/inc/player_clui.h deleted file mode 100644 index a930918..0000000 --- a/modules/player/inc/player_clui.h +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_PLAYER_CLUI_H - # define MSW_PLAYER_CLUI_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* struct Game_Iface_... */ - #include "game_iface.h" - - #include "player_iface.h" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_CLUI_Char { - PLAYER_CLUI_CHAR_ERROR = 'X', - PLAYER_CLUI_CHAR_KBOOM = '#', - PLAYER_CLUI_CHAR_HIDDEN_FIELD = '+', - PLAYER_CLUI_CHAR_HIDDEN_MINE = '*', - PLAYER_CLUI_CHAR_HIDDEN_SAFE = '-', - PLAYER_CLUI_CHAR_SAFE_MINE = 'v', - PLAYER_CLUI_CHAR_0 = ' ', - PLAYER_CLUI_CHAR_1 = '1', - PLAYER_CLUI_CHAR_2 = '2', - PLAYER_CLUI_CHAR_3 = '3', - PLAYER_CLUI_CHAR_4 = '4', - PLAYER_CLUI_CHAR_5 = '5', - PLAYER_CLUI_CHAR_6 = '6', - PLAYER_CLUI_CHAR_7 = '7', - PLAYER_CLUI_CHAR_8 = '8', - PLAYER_CLUI_CHAR_FLAG = '!', - PLAYER_CLUI_CHAR_FLAG_FALSE = 'F', - PLAYER_CLUI_CHAR_POSSIBLE = '?', - PLAYER_CLUI_CHAR_POSSIBLE_FALSE = 'f' - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -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_save_name (const char *fpath, char *fname, int destsize); -void player_clui_score_name (char *player_name, int destsize); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* player_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/inc/player_gui.h b/modules/player/inc/player_gui.h deleted file mode 100644 index 9cac01f..0000000 --- a/modules/player/inc/player_gui.h +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_PLAYER_GUI_H - # define MSW_PLAYER_GUI_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* struct Game_Iface_... */ - #include "game_iface.h" - - #include "player_iface.h" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_GUI_Char { - PLAYER_GUI_CHAR_ERROR = 'X', - PLAYER_GUI_CHAR_KBOOM = '#', - PLAYER_GUI_CHAR_HIDDEN_FIELD = '+', - PLAYER_GUI_CHAR_HIDDEN_MINE = '*', - PLAYER_GUI_CHAR_HIDDEN_SAFE = '-', - PLAYER_GUI_CHAR_SAFE_MINE = 'v', - PLAYER_GUI_CHAR_0 = ' ', - PLAYER_GUI_CHAR_1 = '1', - PLAYER_GUI_CHAR_2 = '2', - PLAYER_GUI_CHAR_3 = '3', - PLAYER_GUI_CHAR_4 = '4', - PLAYER_GUI_CHAR_5 = '5', - PLAYER_GUI_CHAR_6 = '6', - PLAYER_GUI_CHAR_7 = '7', - PLAYER_GUI_CHAR_8 = '8', - PLAYER_GUI_CHAR_FLAG = '!', - PLAYER_GUI_CHAR_FLAG_FALSE = 'F', - PLAYER_GUI_CHAR_POSSIBLE = '?', - PLAYER_GUI_CHAR_POSSIBLE_FALSE = 'f' - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void player_gui_init (struct Player_Iface_Position *pos, - int *action); - -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, - const struct Player_Iface_Position *pos, - const char *title, const char *subtitle); - -void player_gui_save_name (const char *fpath, char *fname, int destsize); -void player_gui_score_name (char *player_name, int destsize); -void player_gui_cleanup (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* player_gui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/inc/player_iface.h b/modules/player/inc/player_iface.h deleted file mode 100644 index d936dc6..0000000 --- a/modules/player/inc/player_iface.h +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_PLAYER_IFACE_H - # define MSW_PLAYER_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* struct Game_Iface_... */ - #include "game_iface.h" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - PLAYER_IFACE_FOO = 0, - PLAYER_IFACE_CLUI, - PLAYER_IFACE_TUI, - PLAYER_IFACE_GUI - }; - - enum Player_Iface_Action { - PLAYER_IFACE_ACT_FOO, - PLAYER_IFACE_ACT_STEP, - PLAYER_IFACE_ACT_FLAG, - PLAYER_IFACE_ACT_FLAG_POSSIBLE, - PLAYER_IFACE_ACT_RM_FLAG, - - PLAYER_IFACE_ACT_PAUSE, - PLAYER_IFACE_ACT_SAVE, - PLAYER_IFACE_ACT_XYZZY_ON, - PLAYER_IFACE_ACT_XYZZY_OFF, - PLAYER_IFACE_ACT_XYZZY_LIN, - PLAYER_IFACE_ACT_XYZZY_P, - PLAYER_IFACE_ACT_XYZZY_NP, - PLAYER_IFACE_ACT_QUIT, - - PLAYER_IFACE_ACT_MOVE_UP, - PLAYER_IFACE_ACT_MOVE_DOWN, - PLAYER_IFACE_ACT_MOVE_RIGHT, - PLAYER_IFACE_ACT_MOVE_LEFT, - PLAYER_IFACE_ACT_HIGHLIGHT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Player_Iface_Position { - int rows; - int cols; - int row; - int col; - int highlight; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int player_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void player_iface_init (int rows, int cols); -int player_iface_start (int *row, int *col); -void player_iface (const struct Game_Iface_Out *out, - const struct Game_Iface_Score *score, - struct Game_Iface_In *in); -void player_iface_save_name (const char *fpath, char *fname, int destsize); -void player_iface_score_name (char *player_name, int destsize); -void player_iface_cleanup (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* player_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/inc/player_tui.h b/modules/player/inc/player_tui.h deleted file mode 100644 index 4af3cae..0000000 --- a/modules/player/inc/player_tui.h +++ /dev/null @@ -1,114 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_PLAYER_TUI_H - # define MSW_PLAYER_TUI_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - -/* Project -------------------------------------------------------------------*/ - /* struct Game_Iface_... */ - #include "game_iface.h" - - #include "player_iface.h" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_TUI_Char { - PLAYER_TUI_CHAR_ERROR = 'X', - PLAYER_TUI_CHAR_KBOOM = '#', - PLAYER_TUI_CHAR_HIDDEN_FIELD = '+', - PLAYER_TUI_CHAR_HIDDEN_MINE = '*', - PLAYER_TUI_CHAR_HIDDEN_SAFE = '-', - PLAYER_TUI_CHAR_SAFE_MINE = 'v', - PLAYER_TUI_CHAR_0 = ' ', - PLAYER_TUI_CHAR_1 = '1', - PLAYER_TUI_CHAR_2 = '2', - PLAYER_TUI_CHAR_3 = '3', - PLAYER_TUI_CHAR_4 = '4', - PLAYER_TUI_CHAR_5 = '5', - PLAYER_TUI_CHAR_6 = '6', - PLAYER_TUI_CHAR_7 = '7', - PLAYER_TUI_CHAR_8 = '8', - PLAYER_TUI_CHAR_FLAG = '!', - PLAYER_TUI_CHAR_FLAG_FALSE = 'F', - PLAYER_TUI_CHAR_POSSIBLE = '?', - PLAYER_TUI_CHAR_POSSIBLE_FALSE = 'f' - }; - - enum Color_Pairs { - /* Clear */ - PAIR_1 = 1, - PAIR_2, - PAIR_3, - PAIR_4, - PAIR_5, - PAIR_6, - PAIR_7, - PAIR_8, - PAIR_BLANK, - /* Hidden */ - PAIR_MINE, - PAIR_HIDDEN, - /* Possible */ - PAIR_fail, - PAIR_POSSIBLE, - /* Flag */ - PAIR_FAIL, - PAIR_FLAG, - /* kboom */ - PAIR_KBOOM, - /* Highlight */ - PAIR_HILITE, - - /* Terminal colors */ - PAIR_TERM - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern bool flag_color; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void player_tui_init (int rows, int cols); - -int player_tui_start (const struct Player_Iface_Position *position, - const char *title, const char *subtitle, - int *action); - -int player_tui (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position, - const char *title, const char *subtitle, - int *action); - -void player_tui_save_name (const char *fpath, char *fname, int destsize); -void player_tui_score_name (char *player_name, int destsize); -void player_tui_cleanup (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* player_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c deleted file mode 100644 index 7ff3e8c..0000000 --- a/modules/player/src/player_clui.c +++ /dev/null @@ -1,500 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - - #include "game_iface.h" - #include "player_iface.h" - - #include "player_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ -/* Static --------------------------------------------------------------------*/ -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 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 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_start (void); -static void show_help_play (void); -static void show_help_pause (void); -static void show_help_xyzzy (void); -static void show_help_cheat (void); -static void show_help_safe (void); -static void show_help_gameover (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void player_clui_start (const struct Player_Iface_Position *position, - const char *title, const char *subtitle, - int *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) -{ - - if (oldaction != PLAYER_IFACE_ACT_FOO) { - show_help(board); - show_board(board, position, title, subtitle); - } - *action = usr_input(); - oldaction = *action; -} - -void player_clui_save_name (const char *fpath, char *fname, int destsize) -{ - - (void)fpath; - - printf("File name:\n"); - fgets(fname, destsize, stdin); -} - -void player_clui_score_name (char *player_name, int destsize) -{ - - printf("Your name:\n"); - fgets(player_name, destsize, stdin); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Start * * * * * * * - * * * * * * * * * */ -static void show_board_start(const struct Player_Iface_Position *position, - const char *title, const char *subtitle) -{ - - printf("________________________________________________________________________________\n"); - board_loop_start(position); - printf("%s - %s\n", subtitle, title); - printf("--------------------------------------------------------------------------------\n"); -} - -static void board_loop_start(const struct Player_Iface_Position *position) -{ - int i; - int j; - char c; - - putchar('\n'); - for (i = 0; i < position->rows; i++) { - for (j = 0; j < position->cols; j++) { - c = PLAYER_CLUI_CHAR_HIDDEN_FIELD; - - /* Print char */ - if (i == position->row && j == position->col) { - putchar('<'); - putchar(c); - putchar('>'); - } else { - putchar(' '); - putchar(c); - putchar(' '); - } - } - putchar('\n'); - } - putchar('\n'); -} - -/* * * * * * * * * * - * * * Play * * * * * * - * * * * * * * * * */ -static void show_board (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position, - const char *title, const char *subtitle) -{ - - printf("________________________________________________________________________________\n"); - board_loop(board, position); - printf("%s - %s\n", subtitle, title); - printf("--------------------------------------------------------------------------------\n"); - -} - -static void board_loop (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position) -{ - int i; - int j; - char c; - - putchar('\n'); - for (i = 0; i < board->rows; i++) { - for (j = 0; j < board->cols; j++) { - c = set_char(board->visible[i][j]); - - /* Print char */ - if (i == position->row && j == position->col) { - putchar('<'); - putchar(c); - putchar('>'); - } else { - putchar(' '); - putchar(c); - putchar(' '); - } - } - putchar('\n'); - } - putchar('\n'); -} - -static char set_char (int game_iface_visible) -{ - char c; - - switch (game_iface_visible) { - case GAME_IFACE_VIS_KBOOM: - c = PLAYER_CLUI_CHAR_KBOOM; - break; - case GAME_IFACE_VIS_HIDDEN_FIELD: - c = PLAYER_CLUI_CHAR_HIDDEN_FIELD; - break; - case GAME_IFACE_VIS_HIDDEN_MINE: - c = PLAYER_CLUI_CHAR_HIDDEN_MINE; - break; - case GAME_IFACE_VIS_HIDDEN_SAFE: - c = PLAYER_CLUI_CHAR_HIDDEN_SAFE; - break; - case GAME_IFACE_VIS_SAFE_MINE: - c = PLAYER_CLUI_CHAR_SAFE_MINE; - break; - case GAME_IFACE_VIS_0: - c = PLAYER_CLUI_CHAR_0; - break; - case GAME_IFACE_VIS_1: - c = PLAYER_CLUI_CHAR_1; - break; - case GAME_IFACE_VIS_2: - c = PLAYER_CLUI_CHAR_2; - break; - case GAME_IFACE_VIS_3: - c = PLAYER_CLUI_CHAR_3; - break; - case GAME_IFACE_VIS_4: - c = PLAYER_CLUI_CHAR_4; - break; - case GAME_IFACE_VIS_5: - c = PLAYER_CLUI_CHAR_5; - break; - case GAME_IFACE_VIS_6: - c = PLAYER_CLUI_CHAR_6; - break; - case GAME_IFACE_VIS_7: - c = PLAYER_CLUI_CHAR_7; - break; - case GAME_IFACE_VIS_8: - c = PLAYER_CLUI_CHAR_8; - break; - case GAME_IFACE_VIS_FLAG: - c = PLAYER_CLUI_CHAR_FLAG; - break; - case GAME_IFACE_VIS_FLAG_FALSE: - c = PLAYER_CLUI_CHAR_FLAG_FALSE; - break; - case GAME_IFACE_VIS_POSSIBLE: - c = PLAYER_CLUI_CHAR_POSSIBLE; - break; - case GAME_IFACE_VIS_POSSIBLE_FALSE: - c = PLAYER_CLUI_CHAR_POSSIBLE_FALSE; - break; - default: - c = PLAYER_CLUI_CHAR_ERROR; - break; - } - - return c; -} - -/* * * * * * * * * * - * * * Input * * * * * * * - * * * * * * * * * */ -static int usr_input (void) -{ - char buff [BUFF_SIZE]; - char c; - int action; - char *p; - - action = PLAYER_IFACE_ACT_FOO; - - /* Wait for input */ - buff[0] = '\0'; - c = '\0'; - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - p = buff; - - /* Interpret input */ - if (sscanf(p, "%c", &c) != 1) - goto err_sscanf; - p++; - switch (c) { - /* Escape sequence */ - case 27: - /* Arrows */ - if (sscanf(p, "%c", &c) != 1) - goto err_sscanf; - p++; - switch (c) { - case 91: - if (sscanf(p, "%c", &c) != 1) - goto err_sscanf; - p++; - switch (c) { - case 65: - action = PLAYER_IFACE_ACT_MOVE_UP; - break; - - case 66: - action = PLAYER_IFACE_ACT_MOVE_DOWN; - break; - - case 67: - action = PLAYER_IFACE_ACT_MOVE_RIGHT; - break; - - case 68: - action = PLAYER_IFACE_ACT_MOVE_LEFT; - break; - } - break; - } - break; - - case 'h': - action = PLAYER_IFACE_ACT_MOVE_LEFT; - break; - - case 'j': - action = PLAYER_IFACE_ACT_MOVE_DOWN; - break; - - case 'k': - action = PLAYER_IFACE_ACT_MOVE_UP; - break; - - case 'l': - action = PLAYER_IFACE_ACT_MOVE_RIGHT; - break; - - case '+': - action = PLAYER_IFACE_ACT_STEP; - break; - - case ' ': - action = PLAYER_IFACE_ACT_FLAG; - break; - - case 'f': - action = PLAYER_IFACE_ACT_FLAG_POSSIBLE; - break; - - /* ASCII 0x08 is BS */ - case 0x7F: - case 0x08: - action = PLAYER_IFACE_ACT_RM_FLAG; - break; - - case 'p': - action = PLAYER_IFACE_ACT_PAUSE; - break; - - case 's': - action = PLAYER_IFACE_ACT_SAVE; - break; - - case 'x': - /* Special sequence "xyzzy" */ - 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; - - 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; - } - - -err_sscanf: -err_fgets: - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (const struct Game_Iface_Out *board) -{ - - 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; - } -} - -static void show_help_start (void) -{ - - printf("Move |Step |Quit |Confirm\n"); - printf(" hjkl | + | q | Enter\n"); -} - -static void show_help_play (void) -{ - - printf("Move |Step |Flag |? |Remove |Pause |Save |Quit |Confirm\n"); - printf(" hjkl | + | Space| f| BS | p | s | q | Enter\n"); -} - -static void show_help_pause (void) -{ - - printf("Continue |Save |Quit |Confirm\n"); - printf(" p | s | q | Enter"); -} - -static void show_help_xyzzy (void) -{ - - printf("XYZZY |Move |Step |Flag |? |Remove |Save |Quit |Confirm\n"); - printf(" 0 1 2| hjkl | + | Space| f| BS | s | q | Enter\n"); -} - -static void show_help_cheat (void) -{ - - printf("Move |Step |Flag |? |Remove |Save |Quit |Confirm\n"); - printf(" hjkl | + | Space| f| BS | s | q | Enter\n"); -} - -static void show_help_safe (void) -{ - - printf("Save |Quit |Confirm\n"); - printf(" s | q | Enter\n"); -} - -static void show_help_gameover (void) -{ - - printf("Quit |Confirm\n"); - printf(" q | Enter\n"); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/src/player_gui.c b/modules/player/src/player_gui.c deleted file mode 100644 index fcbad71..0000000 --- a/modules/player/src/player_gui.c +++ /dev/null @@ -1,946 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - #include - - #include - - #include "libalx/io/alx_input.h" - - #include "game_iface.h" - #include "menu_gui.h" - #include "player_iface.h" - - #include "player_gui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LINE_SIZE (80) - # define REFRESH_TIME_MS (100) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Buttons { - BTN_CH_OFF = 0, - BTN_CH_1, - BTN_CH_2, - BTN_SAVE, - BTN_QUIT, - BTN_QTTY - }; - - enum TButtons { - TBTN_PAUSE, - TBTN_QTTY - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Label_Data { - GtkWidget *ptr; - char text [LINE_SIZE]; - }; - - struct Field_Data { - GtkWidget *ptr; - char ch; - int r; - int c; - int *row; - int *col; - int *act; - }; - - struct Button_Data { - GtkWidget *ptr; - char text [LINE_SIZE]; - int val; - int *act; - }; - - struct TButton_Data { - GtkWidget *ptr; - char text [LINE_SIZE]; - char text2 [LINE_SIZE]; - int val; - int val2; - int *act; - }; - - struct Entry_fname_Data { - GtkWidget *ptr; - struct Label_Data lbl; - const char *fpath; - char *fname; - }; - - struct Entry_str_Data { - GtkWidget *ptr; - struct Label_Data lbl; - char *str; - int strsize; - }; - - struct PBar_Data { - GtkWidget *ptr; - double frac; - char text [LINE_SIZE]; - }; - - struct EBox_Data { - GtkWidget *ptr; - int val; - int *act; - }; - - struct Timeout_Data { - int id; - int val; - int *act; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -static GtkWidget *box; -static GtkWidget *box_help; -static GtkWidget *box_help_in; -static struct Button_Data button [BTN_QTTY]; -static struct TButton_Data tbutton [TBTN_QTTY]; -static struct Entry_str_Data entry_name; -static struct Entry_fname_Data entry_fname; -static GtkWidget *box_board; -static GtkWidget *box_board_in; -static struct PBar_Data pbar_board_tit; -// static GtkWidget *box_board_tit; -static GtkWidget *box_board_tab; -static GtkWidget *table_board; -static struct Field_Data field [ROWS_GUI_MAX] [COLS_GUI_MAX]; -static struct EBox_Data ebox_cheat; -// static GtkWidget *box_board_stit; -static struct Label_Data label_stit; -static int last_help; -static struct Timeout_Data timeout; - -static int state; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Start */ -static void board_init (const struct Player_Iface_Position *pos, - int *action); -static void show_board_start(const struct Player_Iface_Position *pos, - const char *title, const char *subtitle); - -static void board_loop_start(const struct Player_Iface_Position *pos); - - /* Play */ -static void show_board (const struct Game_Iface_Out *board, - const char *title, const char *subtitle); - -static void board_loop (const struct Game_Iface_Out *board); - -static char set_char (int game_iface_visible); -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_start (void); -static void show_help_play (void); -static void show_help_pause (void); -static void show_help_xyzzy (void); -static void show_help_cheat (void); -static void show_help_safe (void); -static void show_help_gameover (void); - /* Input */ -static gboolean callback_field (GtkWidget *widget, - GdkEventButton *event, - void *data); -static gboolean callback_ebox (GtkWidget *widget, - GdkEventButton *event, - void *data); -static void callback_button (GtkWidget *widget, void *data); -static gboolean callback_tbutton (GtkWidget *widget, void *data); -static void callback_entry_fname (GtkWidget *widget, void *data); -static void callback_entry_str (GtkWidget *widget, void *data); -static gboolean callback_timeout (void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -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); - - /* Structure */ - GtkWidget *separator; - box_help = gtk_vbox_new(true, 0); - separator = gtk_vseparator_new(); - box_board = gtk_vbox_new(false, 0); - gtk_box_pack_start(GTK_BOX(box), box_help, false, false, 5); - gtk_box_pack_start(GTK_BOX(box), separator, false, false, 5); - gtk_box_pack_start(GTK_BOX(box), box_board, true, true, 5); - - help_init(action); - board_init(pos, action); - - /* Board fields */ - 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 = &(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", - G_CALLBACK(callback_field), (void *)&field[i][j]); - gtk_table_attach_defaults(GTK_TABLE(table_board), field[i][j].ptr, - field[i][j].c, field[i][j].c + 1, - field[i][j].r, field[i][j].r + 1); - } - } - - /* Refresh */ - gtk_widget_show_all(window_gui); -} - -int player_gui_start (const struct Player_Iface_Position *pos, - const char *title, const char *subtitle) -{ - - show_help_start(); - show_board_start(pos, title, subtitle); - - /* Refresh */ - gtk_widget_show(box); - gtk_widget_show(window_gui); - - gtk_main(); - - return 0; -} - -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, title, subtitle); - - /* Refresh */ - gtk_widget_show(box); - gtk_widget_show(window_gui); - - gtk_main(); - - return 0; -} - -void player_gui_save_name (const char *fpath, char *fname, int destsize) -{ - - entry_fname.fpath = fpath; - entry_fname.fname = fname; - - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_hide(button[BTN_SAVE].ptr); - gtk_widget_show(entry_fname.lbl.ptr); - gtk_widget_show(entry_fname.ptr); - gtk_widget_hide(button[BTN_QUIT].ptr); - - gtk_widget_hide(box_board); - - gtk_main(); - - gtk_widget_show(box_board); - - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - - /* Update last_help */ - last_help = GAME_IFACE_STATE_FOO; -} - -void player_gui_score_name (char *player_name, int destsize) -{ - - entry_name.str = player_name; - entry_name.strsize = destsize; - - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_hide(button[BTN_SAVE].ptr); - gtk_widget_show(entry_name.lbl.ptr); - gtk_widget_show(entry_name.ptr); - gtk_widget_hide(button[BTN_QUIT].ptr); - - gtk_widget_hide(box_board); - - gtk_main(); - - gtk_widget_show(box_board); - - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - - /* Update last_help */ - last_help = GAME_IFACE_STATE_FOO; -} - -void player_gui_cleanup (void) -{ - - gtk_widget_destroy(box); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Start * * * * * * * - * * * * * * * * * */ -static void board_init (const struct Player_Iface_Position *pos, - int *action) -{ - GtkWidget *separator[2]; - - /* Box */ - 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) */ - pbar_board_tit.ptr = gtk_progress_bar_new(); -// box_board_tit = gtk_vbox_new(false, 0); - gtk_box_pack_start(GTK_BOX(box_board_in), pbar_board_tit.ptr, false, false, 0); -// gtk_box_pack_start(GTK_BOX(box_board_in), box_board_tit, false, false, 0); - gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar_board_tit.ptr), "NEW"); -// gtk_box_pack_start(GTK_BOX(box_board_tit), label[0].ptr, false, false, 0); - - /* Pogress bar */ - gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(pbar_board_tit.ptr), GTK_PROGRESS_LEFT_TO_RIGHT); - - /* Separator */ - 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); - gtk_box_pack_start(GTK_BOX(box_board_in), box_board_tab, true, true, 0); - 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(); - 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); - 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"); - 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; - 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; - - /* Refresh */ - gtk_widget_show_all(box_board); -} - -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); - - /* Progress bar */ - pbar_board_tit.frac = 0; - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar_board_tit.ptr), pbar_board_tit.frac); - - /* Board */ - board_loop_start(pos); - - /* Subtitle */ - snprintf(label_stit.text, LINE_SIZE, subtitle); - gtk_label_set_text(GTK_LABEL(label_stit.ptr), label_stit.text); - - /* Refresh */ - gtk_widget_show_all(box_board); -} - -static void board_loop_start(const struct Player_Iface_Position *pos) -{ - int i; - int j; - char c; - - c = PLAYER_GUI_CHAR_HIDDEN_FIELD; - - for (i = 0; i < pos->rows; i++) { - for (j = 0; j < pos->cols; j++) { - field[i][j].ch = c; - show_char(&field[i][j]); - } - } -} - -/* * * * * * * * * * - * * * Play * * * * * * - * * * * * * * * * */ -static void show_board (const struct Game_Iface_Out *board, - 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); - - /* Progress bar */ - if (board->flags % board->mines) { - /* This is a trick to have (frac <= 1) instead of (frac < 1) */ - pbar_board_tit.frac = ((double)board->flags) / ((double)board->mines); - pbar_board_tit.frac = fmod(pbar_board_tit.frac, 1); - } else if (board->flags) { - pbar_board_tit.frac = 1; - } else { - pbar_board_tit.frac = 0; - } - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pbar_board_tit.ptr), pbar_board_tit.frac); - - /* Board */ - board_loop(board); - - /* Subtitle */ - snprintf(label_stit.text, LINE_SIZE, subtitle); - gtk_label_set_text(GTK_LABEL(label_stit.ptr), label_stit.text); - - /* Timeout */ - if (board->state == GAME_IFACE_STATE_PLAYING) - timeout.id = g_timeout_add_seconds(1, callback_timeout, (void *)&timeout); - - /* Refresh */ - gtk_widget_show_all(box_board); -} - -static void board_loop (const struct Game_Iface_Out *board) -{ - int i; - int j; - - for (i = 0; i < board->rows; i++) { - for (j = 0; j < board->cols; j++) { - field[i][j].ch = set_char(board->visible[i][j]); - show_char(&field[i][j]); - } - } -} - -static char set_char (int game_iface_visible) -{ - char c; - - switch (game_iface_visible) { - case GAME_IFACE_VIS_KBOOM: - c = PLAYER_GUI_CHAR_KBOOM; - break; - case GAME_IFACE_VIS_HIDDEN_FIELD: - c = PLAYER_GUI_CHAR_HIDDEN_FIELD; - break; - case GAME_IFACE_VIS_HIDDEN_MINE: - c = PLAYER_GUI_CHAR_HIDDEN_MINE; - break; - case GAME_IFACE_VIS_HIDDEN_SAFE: - c = PLAYER_GUI_CHAR_HIDDEN_SAFE; - break; - case GAME_IFACE_VIS_SAFE_MINE: - c = PLAYER_GUI_CHAR_SAFE_MINE; - break; - case GAME_IFACE_VIS_0: - c = PLAYER_GUI_CHAR_0; - break; - case GAME_IFACE_VIS_1: - c = PLAYER_GUI_CHAR_1; - break; - case GAME_IFACE_VIS_2: - c = PLAYER_GUI_CHAR_2; - break; - case GAME_IFACE_VIS_3: - c = PLAYER_GUI_CHAR_3; - break; - case GAME_IFACE_VIS_4: - c = PLAYER_GUI_CHAR_4; - break; - case GAME_IFACE_VIS_5: - c = PLAYER_GUI_CHAR_5; - break; - case GAME_IFACE_VIS_6: - c = PLAYER_GUI_CHAR_6; - break; - case GAME_IFACE_VIS_7: - c = PLAYER_GUI_CHAR_7; - break; - case GAME_IFACE_VIS_8: - c = PLAYER_GUI_CHAR_8; - break; - case GAME_IFACE_VIS_FLAG: - c = PLAYER_GUI_CHAR_FLAG; - break; - case GAME_IFACE_VIS_FLAG_FALSE: - c = PLAYER_GUI_CHAR_FLAG_FALSE; - break; - case GAME_IFACE_VIS_POSSIBLE: - c = PLAYER_GUI_CHAR_POSSIBLE; - break; - case GAME_IFACE_VIS_POSSIBLE_FALSE: - c = PLAYER_GUI_CHAR_POSSIBLE_FALSE; - break; - default: - c = PLAYER_GUI_CHAR_ERROR; - break; - } - - return c; -} - -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); -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -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); - - /* Text */ - snprintf(button[BTN_CH_OFF].text, LINE_SIZE, "[_0] Cheats off"); - snprintf(button[BTN_CH_1].text, LINE_SIZE, "Cheat _1"); - snprintf(button[BTN_CH_2].text, LINE_SIZE, "Cheat _2"); - snprintf(tbutton[TBTN_PAUSE].text, LINE_SIZE, "_Pause"); - snprintf(tbutton[TBTN_PAUSE].text2, LINE_SIZE, "[_P] Continue"); - snprintf(button[BTN_SAVE].text, LINE_SIZE, "_Save"); - snprintf(entry_fname.lbl.text, LINE_SIZE, "File name:"); - snprintf(entry_name.lbl.text, LINE_SIZE, "Your name:"); - snprintf(button[BTN_QUIT].text, LINE_SIZE, "_Quit"); - - /* 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; - /* 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; - - /* 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); - - /* Toggle buttons */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tbutton[TBTN_PAUSE].ptr), false); - - /* Events */ - g_signal_connect(button[BTN_CH_OFF].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[BTN_CH_OFF]); - g_signal_connect(button[BTN_CH_1].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[BTN_CH_1]); - g_signal_connect(button[BTN_CH_2].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[BTN_CH_2]); - g_signal_connect(tbutton[TBTN_PAUSE].ptr, "toggled", - G_CALLBACK(callback_tbutton), (void *)&tbutton[TBTN_PAUSE]); - g_signal_connect(button[BTN_SAVE].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[BTN_SAVE]); - g_signal_connect(entry_fname.ptr, "activate", - G_CALLBACK(callback_entry_fname), (void *)&entry_fname); - g_signal_connect(entry_name.ptr, "activate", - G_CALLBACK(callback_entry_str), (void *)&entry_name); - g_signal_connect(button[BTN_QUIT].ptr, "clicked", - G_CALLBACK(callback_button), (void *)&button[BTN_QUIT]); - - /* Box */ - gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_CH_OFF].ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_CH_1].ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_CH_2].ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), tbutton[TBTN_PAUSE].ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_SAVE].ptr, false, false, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), entry_fname.lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), entry_fname.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), entry_name.lbl.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), entry_name.ptr, true, true, 0); - gtk_box_pack_start(GTK_BOX(box_help_in), button[BTN_QUIT].ptr, false, false, 0); -} - -static void show_help (const struct Game_Iface_Out *board) -{ - - if (last_help != board->state) { - 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; - } - - /* Update last_help */ - last_help = board->state; - - /* Refresh */ - gtk_widget_show(box_help_in); - gtk_widget_show(box_help); - } -} - -static void show_help_start (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_hide(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); - - /* Update last_help */ - last_help = GAME_IFACE_STATE_FOO; - - /* Refresh */ - gtk_widget_show(box_help_in); - gtk_widget_show(box_help); -} - -static void show_help_play (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_show(tbutton[TBTN_PAUSE].ptr); - gtk_widget_show(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -static void show_help_pause (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_show(tbutton[TBTN_PAUSE].ptr); - gtk_widget_show(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -static void show_help_xyzzy (void) -{ - - /* Show & hide */ - gtk_widget_show(button[BTN_CH_OFF].ptr); - gtk_widget_show(button[BTN_CH_1].ptr); - gtk_widget_show(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_show(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -static void show_help_cheat (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_show(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -static void show_help_safe (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_show(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -static void show_help_gameover (void) -{ - - /* Show & hide */ - gtk_widget_hide(button[BTN_CH_OFF].ptr); - gtk_widget_hide(button[BTN_CH_1].ptr); - gtk_widget_hide(button[BTN_CH_2].ptr); - gtk_widget_hide(tbutton[TBTN_PAUSE].ptr); - gtk_widget_hide(button[BTN_SAVE].ptr); - gtk_widget_hide(entry_fname.lbl.ptr); - gtk_widget_hide(entry_fname.ptr); - gtk_widget_hide(entry_name.lbl.ptr); - gtk_widget_hide(entry_name.ptr); - gtk_widget_show(button[BTN_QUIT].ptr); -} - -/* * * * * * * * * * - * * * Input * * * * * * * - * * * * * * * * * */ -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); - - field_ij = ((struct Field_Data *)data); - *(field_ij->row) = field_ij->r; - *(field_ij->col) = field_ij->c; - - switch (event->button) { - case 1: - //1 is left mouse btn - if (event->type == GDK_BUTTON_PRESS) - *(field_ij->act) = PLAYER_IFACE_ACT_STEP; - break; - - case 3: - //3 is right mouse btn - if (event->type == GDK_BUTTON_PRESS) - *(field_ij->act) = PLAYER_IFACE_ACT_FLAG; - break; - } - - gtk_main_quit(); - - return false; -} - -static gboolean callback_ebox (GtkWidget *widget, - GdkEventButton *event, - void *data) -{ - struct EBox_Data *ebox; - - if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) - g_source_remove(timeout.id); - - ebox = ((struct EBox_Data *)data); - - switch (event->button) { - case 1: - //1 is left mouse btn - if (event->type == GDK_BUTTON_PRESS) - *(ebox->act) = ebox->val; - else if (event->type == GDK_2BUTTON_PRESS) - ; /* TODO */ - break; - - case 3: - //3 is right mouse btn - break; - } - - gtk_main_quit(); - - return false; -} - -static void callback_button (GtkWidget *widget, void *data) -{ - struct Button_Data *button; - - if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) - g_source_remove(timeout.id); - - button = ((struct Button_Data *)data); - *(button->act) = button->val; - - gtk_main_quit(); - -} - -static gboolean callback_tbutton (GtkWidget *widget, void *data) -{ - struct TButton_Data *tbutton; - - if ((state == GAME_IFACE_STATE_PLAYING) && timeout.id) - g_source_remove(timeout.id); - - tbutton = ((struct TButton_Data *)data); - - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { - /* If control reaches here, the toggle button is down */ - *(tbutton->act) = tbutton->val; - gtk_button_set_label(GTK_BUTTON(tbutton[TBTN_PAUSE].ptr), tbutton[TBTN_PAUSE].text2); - } else { - /* If control reaches here, the toggle button is up */ - *(tbutton->act) = tbutton->val2; - gtk_button_set_label(GTK_BUTTON(tbutton[TBTN_PAUSE].ptr), tbutton[TBTN_PAUSE].text); - } - - gtk_main_quit(); - - return false; -} - -static void callback_entry_fname (GtkWidget *widget, void *data) -{ - struct Entry_fname_Data *entry; - const char *str; - int err; - 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); - - if (err) { - snprintf(buff, LINE_SIZE, "Error %i", err); - gtk_entry_set_text(GTK_ENTRY(entry->ptr), buff); - gtk_editable_select_region(GTK_EDITABLE(entry->ptr), - 0, GTK_ENTRY(entry->ptr)->text_length); - } - - gtk_main_quit(); -} - -static void callback_entry_str (GtkWidget *widget, void *data) -{ - struct Entry_str_Data *entry; - 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); - - gtk_main_quit(); -} - -static gboolean callback_timeout (void *data) -{ - struct Timeout_Data *tout; - - tout = ((struct Timeout_Data *)data); - *(tout->act) = tout->val; - - gtk_main_quit(); - - return false; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/src/player_iface.c b/modules/player/src/player_iface.c deleted file mode 100644 index 537afb0..0000000 --- a/modules/player/src/player_iface.c +++ /dev/null @@ -1,419 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - - #include "game_iface.h" - #include "player_clui.h" - #include "player_tui.h" - #include "player_gui.h" - - #include "player_iface.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define TITLE_SIZE (20) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - int player_iface_mode; -/* Static --------------------------------------------------------------------*/ -static struct Player_Iface_Position player_iface_position; -static int player_action; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Actions */ -static void player_iface_act (struct Game_Iface_In *in); - - /* Actions: game iface */ -static void player_iface_act_start (void); -static void player_iface_act_play (struct Game_Iface_In *in); -static void player_iface_act_game (struct Game_Iface_In *in); - - /* Actions: player iface */ -static void player_iface_move_up (void); -static void player_iface_move_down (void); -static void player_iface_move_right (void); -static void player_iface_move_left (void); -static void highlight_cursor (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void player_iface_init (int rows, int cols) -{ - - player_iface_position.rows = rows; - player_iface_position.cols = cols; - - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - break; - - case PLAYER_IFACE_TUI: - player_tui_init(rows, cols); - break; - - case PLAYER_IFACE_GUI: - player_gui_init(&player_iface_position, &player_action); - break; - } -} - -int player_iface_start (int *row, int *col) -{ - char title[TITLE_SIZE]; - char subtitle[TITLE_SIZE]; - int fail; - - snprintf(title, TITLE_SIZE, "Start:"); - snprintf(subtitle, TITLE_SIZE, "00:00 | 0"); - - /* Start position */ - player_iface_position.row = 0; - player_iface_position.col = 0; - player_iface_position.highlight = false; - - /* Loop until first step */ - do { - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - player_clui_start(&player_iface_position, - title, subtitle, &player_action); - break; - - case PLAYER_IFACE_TUI: - player_tui_start(&player_iface_position, - title, subtitle, &player_action); - break; - - case PLAYER_IFACE_GUI: - player_gui_start(&player_iface_position, - title, subtitle); - break; - } - - player_iface_act_start(); - } while ((player_action != PLAYER_IFACE_ACT_STEP) && - (player_action != PLAYER_IFACE_ACT_QUIT)); - - *row = player_iface_position.row; - *col = player_iface_position.col; - - switch (player_action) { - case PLAYER_IFACE_ACT_STEP: - fail = 0; - break; - - case PLAYER_IFACE_ACT_QUIT: - fail = -1; - break; - - default: - fail = -2; - break; - } - return fail; -} - -void player_iface (const struct Game_Iface_Out *out, - const struct Game_Iface_Score *score, - struct Game_Iface_In *in) -{ - char title[TITLE_SIZE]; - char subtitle[TITLE_SIZE]; - int hours; - int mins; - int secs; - - /* Title */ - switch (out->state) { - case GAME_IFACE_STATE_XYZZY: - case GAME_IFACE_STATE_CHEATED: - case GAME_IFACE_STATE_PLAYING: - case GAME_IFACE_STATE_PAUSE: - snprintf(title, TITLE_SIZE, "Mines: %i/%i", - out->flags, out->mines); - break; - - case GAME_IFACE_STATE_GAMEOVER: - snprintf(title, TITLE_SIZE, "GAME OVER"); - break; - - case GAME_IFACE_STATE_SAFE: - snprintf(title, TITLE_SIZE, "You win!"); - break; - } - /* Subtitle */ - if (score->time != CHEATED) { - hours = ((int)score->time / 3600); - mins = (((int)score->time % 3600) / 60); - secs = ((int)score->time % 60); - - if (score->time >= 3600) { - snprintf(subtitle, TITLE_SIZE, "%02i:%02i:%02i | %i", - hours, mins, secs, score->clicks); - } else { - snprintf(subtitle, TITLE_SIZE, "%02i:%02i | %i", - mins, secs, score->clicks); - } - } else { - snprintf(subtitle, TITLE_SIZE, "N/A"); - } - - /* Request player action */ - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - player_clui(out, &player_iface_position, title, subtitle, - &player_action); - break; - case PLAYER_IFACE_TUI: - player_tui(out, &player_iface_position, title, subtitle, - &player_action); - break; - case PLAYER_IFACE_GUI: - player_gui(out, &player_iface_position, title, subtitle); - break; - } - - player_iface_act(in); -} - -void player_iface_save_name (const char *fpath, char *fname, int destsize) -{ - - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - player_clui_save_name(fpath, fname, destsize); - break; - case PLAYER_IFACE_TUI: - player_tui_save_name(fpath, fname, destsize); - break; - case PLAYER_IFACE_GUI: - player_gui_save_name(fpath, fname, destsize); - break; - } -} - -void player_iface_score_name (char *player_name, int destsize) -{ - - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - player_clui_score_name(player_name, destsize); - break; - case PLAYER_IFACE_TUI: - player_tui_score_name(player_name, destsize); - break; - case PLAYER_IFACE_GUI: - player_gui_score_name(player_name, destsize); - break; - } -} - -void player_iface_cleanup (void) -{ - - switch (player_iface_mode) { - case PLAYER_IFACE_CLUI: - break; - case PLAYER_IFACE_TUI: - player_tui_cleanup(); - break; - case PLAYER_IFACE_GUI: - player_gui_cleanup(); - break; - } - fflush(stdout); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Actions * * * * * * - * * * * * * * * * */ -static void player_iface_act (struct Game_Iface_In *in) -{ - - switch (player_action) { - case PLAYER_IFACE_ACT_STEP: - case PLAYER_IFACE_ACT_FLAG: - case PLAYER_IFACE_ACT_FLAG_POSSIBLE: - case PLAYER_IFACE_ACT_RM_FLAG: - player_iface_act_play(in); - break; - case PLAYER_IFACE_ACT_PAUSE: - case PLAYER_IFACE_ACT_SAVE: - case PLAYER_IFACE_ACT_XYZZY_ON: - case PLAYER_IFACE_ACT_XYZZY_OFF: - case PLAYER_IFACE_ACT_XYZZY_LIN: - case PLAYER_IFACE_ACT_XYZZY_P: - case PLAYER_IFACE_ACT_XYZZY_NP: - case PLAYER_IFACE_ACT_QUIT: - player_iface_act_game(in); - break; - case PLAYER_IFACE_ACT_MOVE_UP: - player_iface_move_up(); - break; - case PLAYER_IFACE_ACT_MOVE_DOWN: - player_iface_move_down(); - break; - case PLAYER_IFACE_ACT_MOVE_RIGHT: - player_iface_move_right(); - break; - case PLAYER_IFACE_ACT_MOVE_LEFT: - player_iface_move_left(); - break; - case PLAYER_IFACE_ACT_HIGHLIGHT: - highlight_cursor(); - break; - } -} - -static void player_iface_act_start (void) -{ - - switch (player_action) { - case PLAYER_IFACE_ACT_STEP: - case PLAYER_IFACE_ACT_QUIT: - break; - case PLAYER_IFACE_ACT_MOVE_UP: - player_iface_move_up(); - break; - case PLAYER_IFACE_ACT_MOVE_DOWN: - player_iface_move_down(); - break; - case PLAYER_IFACE_ACT_MOVE_RIGHT: - player_iface_move_right(); - break; - case PLAYER_IFACE_ACT_MOVE_LEFT: - player_iface_move_left(); - break; - case PLAYER_IFACE_ACT_HIGHLIGHT: - highlight_cursor(); - break; - } -} - -/* * * * * * * * * * - * * * Actions: game iface * * * * * - * * * * * * * * * */ -static void player_iface_act_play (struct Game_Iface_In *in) -{ - const int r = player_iface_position.row; - const int c = player_iface_position.col; - - switch (player_action) { - case PLAYER_IFACE_ACT_STEP: - in->act_game[r][c] = GAME_IFACE_GAME_ACT_STEP; - break; - case PLAYER_IFACE_ACT_FLAG: - in->act_game[r][c] = GAME_IFACE_GAME_ACT_FLAG; - break; - case PLAYER_IFACE_ACT_FLAG_POSSIBLE: - in->act_game[r][c] = GAME_IFACE_GAME_ACT_FLAG_POSSIBLE; - break; - case PLAYER_IFACE_ACT_RM_FLAG: - in->act_game[r][c] = GAME_IFACE_GAME_ACT_RM_FLAG; - break; - } - - in->action = GAME_IFACE_ACT_PLAY; -} - -static void player_iface_act_game (struct Game_Iface_In *in) -{ - - switch (player_action) { - case PLAYER_IFACE_ACT_PAUSE: - in->action = GAME_IFACE_ACT_PAUSE; - break; - case PLAYER_IFACE_ACT_SAVE: - in->action = GAME_IFACE_ACT_SAVE; - break; - case PLAYER_IFACE_ACT_XYZZY_ON: - in->action = GAME_IFACE_ACT_XYZZY_ON; - break; - case PLAYER_IFACE_ACT_XYZZY_OFF: - in->action = GAME_IFACE_ACT_XYZZY_OFF; - break; - case PLAYER_IFACE_ACT_XYZZY_LIN: - in->action = GAME_IFACE_ACT_XYZZY_LIN; - break; - case PLAYER_IFACE_ACT_XYZZY_P: - in->action = GAME_IFACE_ACT_XYZZY_P; - break; - case PLAYER_IFACE_ACT_XYZZY_NP: - in->action = GAME_IFACE_ACT_XYZZY_NP; - break; - case PLAYER_IFACE_ACT_QUIT: - in->action = GAME_IFACE_ACT_QUIT; - break; - } -} - -/* * * * * * * * * * - * * * Actions: player iface * * * * - * * * * * * * * * */ -static void player_iface_move_up (void) -{ - - if (player_iface_position.row) - (player_iface_position.row)--; - else - player_iface_position.row = player_iface_position.rows - 1; -} - -static void player_iface_move_down (void) -{ - - if (player_iface_position.row != player_iface_position.rows - 1) - (player_iface_position.row)++; - else - player_iface_position.row = 0; -} - -static void player_iface_move_right (void) -{ - - if (player_iface_position.col != player_iface_position.cols - 1) - (player_iface_position.col)++; - else - player_iface_position.col = 0; -} - -static void player_iface_move_left (void) -{ - - if (player_iface_position.col) - (player_iface_position.col)--; - else - player_iface_position.col = player_iface_position.cols - 1; -} - -static void highlight_cursor (void) -{ - - player_iface_position.highlight = !player_iface_position.highlight; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/src/player_tui.c b/modules/player/src/player_tui.c deleted file mode 100644 index 99cba09..0000000 --- a/modules/player/src/player_tui.c +++ /dev/null @@ -1,858 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - - #include "libalx/curses/alx_ncur.h" - - #include "game_iface.h" - - #include "player_iface.h" - - #include "player_tui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define REFRESH_TIME_MS (100) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - bool flag_color; -/* Static --------------------------------------------------------------------*/ -static WINDOW *win_board; -static WINDOW *win_help; -static int last_help; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Start */ -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); - - /* 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 board_loop (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position); - -static void highlight_cursor(int c, - const struct Player_Iface_Position *position); - -static int set_char (int tile); -static void show_char (int row, int col, int c); - /* Input */ -static int usr_input (void); - /* Help */ -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); -static void show_help_xyzzy (void); -static void show_help_cheat (void); -static void show_help_safe (void); -static void show_help_gameover (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void player_tui_init (int rows, int cols) -{ - int h1; - int w1; - int r1; - int c1; - int h2; - int w2; - int r2; - int c2; - - alx_resume_curses(); - - flag_color = false; - if (has_colors()) { - flag_color = true; - /* Clear */ - init_pair(PAIR_1, COLOR_BLUE, COLOR_WHITE); - init_pair(PAIR_2, COLOR_GREEN, COLOR_WHITE); - init_pair(PAIR_3, COLOR_RED, COLOR_WHITE); - init_pair(PAIR_4, COLOR_BLUE, COLOR_WHITE); - init_pair(PAIR_5, COLOR_RED, COLOR_WHITE); - init_pair(PAIR_6, COLOR_CYAN, COLOR_WHITE); - init_pair(PAIR_7, COLOR_BLACK, COLOR_WHITE); - init_pair(PAIR_8, COLOR_BLACK, COLOR_WHITE); - init_pair(PAIR_BLANK, COLOR_BLACK, COLOR_WHITE); - /* Hidden */ - init_pair(PAIR_MINE, COLOR_WHITE, COLOR_BLACK); - init_pair(PAIR_HIDDEN, COLOR_WHITE, COLOR_BLACK); - /* Possible */ - init_pair(PAIR_fail, COLOR_RED, COLOR_BLACK); - init_pair(PAIR_POSSIBLE, COLOR_BLUE, COLOR_BLACK); - /* Flag */ - init_pair(PAIR_FAIL, COLOR_RED, COLOR_BLACK); - init_pair(PAIR_FLAG, COLOR_RED, COLOR_BLACK); - /* Kboom */ - init_pair(PAIR_KBOOM, COLOR_BLACK, COLOR_RED); - /* Highlight */ - init_pair(PAIR_HILITE, COLOR_YELLOW, COLOR_RED); - /* Terminal */ - init_pair(PAIR_TERM, -1, -1); - } - - /* Dimensions: board */ - h1 = rows + 2; - w1 = 2 * cols + 3; - r1 = 0; - c1 = 11; - win_board = newwin(h1, w1, r1, c1); - - /* Dimensions: help */ - 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 */ - keypad(win_board, true); - noecho(); - wtimeout(win_board, REFRESH_TIME_MS); -} - -int player_tui_start (const struct Player_Iface_Position *position, - const char *title, const char *subtitle, - int *action) -{ - - show_help_start(); - show_board_start(position, title, subtitle); - *action = usr_input(); - - return 0; -} - -int player_tui (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position, - const char *title, const char *subtitle, - int *action) -{ - - show_help(board); - show_board(board, position, title, subtitle); - *action = usr_input(); - - return 0; -} - -void player_tui_save_name (const char *fpath, char *fname, int destsize) -{ - int w; - int r; - - w = 60; - r = 10; - alx_w_getfname(fpath, fname, false, w, r, "File name:", NULL); -} - -void player_tui_score_name (char *player_name, int destsize) -{ - int w; - int r; - - w = 60; - r = 10; - alx_w_getstr(player_name, destsize, w, r, "Your name:", NULL); -} - -void player_tui_cleanup (void) -{ - - alx_win_del(win_board); - alx_win_del(win_help); - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* * * * * * * * * * - * * * Start * * * * * * * - * * * * * * * * * */ -static void show_board_start(const struct Player_Iface_Position *position, - const char *title, const char *subtitle) -{ - werase(win_board); - box(win_board, 0, 0); - - alx_ncur_prn_title(win_board, title); - alx_ncur_prn_subtitle(win_board, subtitle); - board_loop_start(position); - wmove(win_board, 1 + position->row, 2 + 2 * position->col); - - wrefresh(win_board); -} - -static void board_loop_start(const struct Player_Iface_Position *position) -{ - int i; - int j; - int k; - int l; - int c; - - c = PLAYER_TUI_CHAR_HIDDEN_FIELD; - - for (i = 0; i < position->rows; i++) { - k = 1 + i; - - /* hidden */ - for (j = 0; j < position->cols; j++) { - l = 2 + 2 * j; - - show_char(k, l, c); - } - } - - /* Highlight cursor */ - if (position->highlight) - highlight_cursor(c, position); -} - -/* * * * * * * * * * - * * * Play * * * * * * - * * * * * * * * * */ -static void show_board (const struct Game_Iface_Out *board, - 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(board, position); - - /* Cursor */ - wmove(win_board, 1 + position->row, 2 + 2 * position->col); - - /* Refresh */ - wrefresh(win_board); -} - -static void board_loop (const struct Game_Iface_Out *board, - const struct Player_Iface_Position *position) -{ - int i; - int j; - int k; - int l; - int c; - - for (i = 0; i < board->rows; i++) { - k = 1 + i; - - /* clear */ - for (j = 0; j < board->cols; j++) { - l = 2 + 2 * j; - if (board->usr[i][j] == GAME_IFACE_USR_CLEAR) { - c = set_char(board->visible[i][j]); - show_char(k, l, c); - } - } - /* xyzzy */ - /* hidden */ - for (j = 0; j < board->cols; j++) { - l = 2 + 2 * j; - if (board->usr[i][j] != GAME_IFACE_USR_CLEAR) { - 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) { - c = set_char(board->visible[i][j]); - show_char(k, l, c); - } - } - } - - /* Highlight cursor */ - if (position->highlight) { - c = set_char(board->visible[position->row][position->col]); - highlight_cursor(c, position); - } -} - -static void highlight_cursor(int c, - const struct Player_Iface_Position *position) -{ - int k; - int l; - int pair; - - k = 1 + position->row; - l = 2 + 2 * position->col; - - pair = PAIR_HILITE; - if (flag_color) - wattron(win_board, A_BOLD | COLOR_PAIR(pair)); - mvwaddch(win_board, k, l - 1, '<'); - mvwaddch(win_board, k, l, c); - mvwaddch(win_board, k, l + 1, '>'); - if (flag_color) - wattroff(win_board, A_BOLD | COLOR_PAIR(pair)); -} - -static int set_char (int tile) -{ - int c; - - switch (tile) { - case GAME_IFACE_VIS_KBOOM: - c = PLAYER_TUI_CHAR_KBOOM; - break; - case GAME_IFACE_VIS_HIDDEN_FIELD: - c = PLAYER_TUI_CHAR_HIDDEN_FIELD; - break; - case GAME_IFACE_VIS_HIDDEN_MINE: - c = PLAYER_TUI_CHAR_HIDDEN_MINE; - break; - case GAME_IFACE_VIS_HIDDEN_SAFE: - c = PLAYER_TUI_CHAR_HIDDEN_SAFE; - break; - case GAME_IFACE_VIS_SAFE_MINE: - c = PLAYER_TUI_CHAR_SAFE_MINE; - break; - case GAME_IFACE_VIS_0: - c = PLAYER_TUI_CHAR_0; - break; - case GAME_IFACE_VIS_1: - c = PLAYER_TUI_CHAR_1; - break; - case GAME_IFACE_VIS_2: - c = PLAYER_TUI_CHAR_2; - break; - case GAME_IFACE_VIS_3: - c = PLAYER_TUI_CHAR_3; - break; - case GAME_IFACE_VIS_4: - c = PLAYER_TUI_CHAR_4; - break; - case GAME_IFACE_VIS_5: - c = PLAYER_TUI_CHAR_5; - break; - case GAME_IFACE_VIS_6: - c = PLAYER_TUI_CHAR_6; - break; - case GAME_IFACE_VIS_7: - c = PLAYER_TUI_CHAR_7; - break; - case GAME_IFACE_VIS_8: - c = PLAYER_TUI_CHAR_8; - break; - case GAME_IFACE_VIS_FLAG: - c = PLAYER_TUI_CHAR_FLAG; - break; - case GAME_IFACE_VIS_FLAG_FALSE: - c = PLAYER_TUI_CHAR_FLAG_FALSE; - break; - case GAME_IFACE_VIS_POSSIBLE: - c = PLAYER_TUI_CHAR_POSSIBLE; - break; - case GAME_IFACE_VIS_POSSIBLE_FALSE: - c = PLAYER_TUI_CHAR_POSSIBLE_FALSE; - break; - default: - c = PLAYER_TUI_CHAR_ERROR; - break; - } - - return c; -} - -static void show_char (int row, int col, int c) -{ - int pair; - - switch (c) { - case PLAYER_TUI_CHAR_1: - pair = PAIR_1; - break; - case PLAYER_TUI_CHAR_2: - pair = PAIR_2; - break; - case PLAYER_TUI_CHAR_3: - pair = PAIR_3; - break; - case PLAYER_TUI_CHAR_4: - pair = PAIR_4; - break; - case PLAYER_TUI_CHAR_5: - pair = PAIR_5; - break; - case PLAYER_TUI_CHAR_6: - pair = PAIR_6; - break; - case PLAYER_TUI_CHAR_7: - pair = PAIR_7; - break; - case PLAYER_TUI_CHAR_8: - pair = PAIR_8; - break; - case PLAYER_TUI_CHAR_0: - pair = PAIR_BLANK; - break; - case PLAYER_TUI_CHAR_HIDDEN_MINE: - case PLAYER_TUI_CHAR_SAFE_MINE: - pair = PAIR_MINE; - break; - case PLAYER_TUI_CHAR_HIDDEN_FIELD: - case PLAYER_TUI_CHAR_HIDDEN_SAFE: - pair = PAIR_HIDDEN; - break; - case PLAYER_TUI_CHAR_POSSIBLE_FALSE: - pair = PAIR_fail; - break; - case PLAYER_TUI_CHAR_POSSIBLE: - pair = PAIR_POSSIBLE; - break; - case PLAYER_TUI_CHAR_FLAG_FALSE: - pair = PAIR_FAIL; - break; - case PLAYER_TUI_CHAR_FLAG: - pair = PAIR_FLAG; - break; - case PLAYER_TUI_CHAR_KBOOM: - pair = PAIR_KBOOM; - break; - default: - pair = PAIR_KBOOM; - break; - } - - if (flag_color) - wattron(win_board, A_BOLD | COLOR_PAIR(pair)); - mvwaddch(win_board, row, col - 1, ' '); - mvwaddch(win_board, row, col, c); - mvwaddch(win_board, row, col + 1, ' '); - if (flag_color) - wattroff(win_board, A_BOLD | COLOR_PAIR(pair)); -} - -/* * * * * * * * * * - * * * Input * * * * * * * - * * * * * * * * * */ -static int usr_input (void) -{ - int c; - int action; - - c = wgetch(win_board); - - switch (c) { - 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; - - /* ASCII 0x08 is BS */ - case KEY_BACKSPACE: - 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); - - c = wgetch(win_board); - if (c == 'y') { - c = wgetch(win_board); - if (c == 'z') { - c = wgetch(win_board); - if (c == 'z') { - c = wgetch(win_board); - if (c == '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; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (const struct Game_Iface_Out *board) -{ - if (last_help == board->state) - return; - - 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; - } - - wrefresh(win_help); - last_help = board->state; -} - -static void show_help_start (void) -{ - int r; - int c; - - werase(win_help); - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c++, "Move:"); - /* hjkl */ - mvwaddch(win_help, r, c, 'h'); - c += 2; - mvwaddch(win_help, r, c, 'j'); - c += 2; - mvwaddch(win_help, r, c, 'k'); - c += 2; - mvwaddch(win_help, r, c, 'l'); - /* Arrows */ - r++; - c = 1; - mvwaddch(win_help, r, c, ACS_LARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_DARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_UARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_RARROW); - - r++; - c = 0; - mvwaddstr(win_help, r++, c, "Cursor:"); - mvwprintw(win_help, r++, c, " %c", 'c'); - - mvwaddstr(win_help, r++, c, "Step:"); - mvwprintw(win_help, r++, c, " Enter / %c", '+'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); - - wrefresh(win_help); - last_help = GAME_IFACE_STATE_FOO; -} - -static void show_help_play (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c++, "Move:"); - /* hjkl */ - mvwaddch(win_help, r, c, 'h'); - c += 2; - mvwaddch(win_help, r, c, 'j'); - c += 2; - mvwaddch(win_help, r, c, 'k'); - c += 2; - mvwaddch(win_help, r, c, 'l'); - /* Arrows */ - r++; - c = 1; - mvwaddch(win_help, r, c, ACS_LARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_DARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_UARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_RARROW); - - r++; - c = 0; - mvwaddstr(win_help, r++, c, "Cursor:"); - mvwprintw(win_help, r++, c, " %c", 'c'); - - mvwaddstr(win_help, r++, c, "Step:"); - mvwprintw(win_help, r++, c, " Enter / %c", '+'); - - mvwaddstr(win_help, r++, c, "Flag:"); - mvwprintw(win_help, r++, c, " Space"); - - mvwaddstr(win_help, r++, c, "Possible:"); - mvwprintw(win_help, r++, c, " %c", 'f'); - - mvwaddstr(win_help, r++, c, "rm flag:"); - mvwprintw(win_help, r++, c, " Backspace"); - - mvwaddstr(win_help, r++, c, "Pause:"); - mvwprintw(win_help, r++, c, " Break / %c", 'p'); - - mvwaddstr(win_help, r++, c, "Save:"); - mvwprintw(win_help, r++, c, " %c", 's'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - -static void show_help_pause (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c, "Cursor:"); - mvwprintw(win_help, r++, c, " %c", 'c'); - - mvwaddstr(win_help, r++, c, "Continue:"); - mvwprintw(win_help, r++, c, " Break / %c", 'p'); - - mvwaddstr(win_help, r++, c, "Save:"); - mvwprintw(win_help, r++, c, " %c", 's'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - -static void show_help_xyzzy (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c++, "XYZZY:"); - mvwprintw(win_help, r, c, "%c", '1'); - c += 2; - mvwprintw(win_help, r, c, "%c", '2'); -// c += 2; -// mvwprintw(win_help, r, c, "%c", 'd'); - - r++; - c = 0; - mvwaddstr(win_help, r++, c, "XYZZY off:"); - mvwprintw(win_help, r++, c, " %c", '0'); - - mvwaddstr(win_help, r++, c++, "Move:"); - /* hjkl */ - mvwaddch(win_help, r, c, 'h'); - c += 2; - mvwaddch(win_help, r, c, 'j'); - c += 2; - mvwaddch(win_help, r, c, 'k'); - c += 2; - mvwaddch(win_help, r, c, 'l'); - /* Arrows */ - r++; - c = 1; - mvwaddch(win_help, r, c, ACS_LARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_DARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_UARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_RARROW); - - r++; - c = 0; - mvwaddstr(win_help, r++, c, "Cursor:"); - mvwprintw(win_help, r++, c, " %c", 'c'); - - mvwaddstr(win_help, r++, c, "Step:"); - mvwprintw(win_help, r++, c, " Enter / %c", '+'); - - mvwaddstr(win_help, r++, c, "Flag:"); - mvwprintw(win_help, r++, c, " Space"); - - mvwaddstr(win_help, r++, c, "Possible:"); - mvwprintw(win_help, r++, c, " %c", 'f'); - - mvwaddstr(win_help, r++, c, "rm flag:"); - mvwprintw(win_help, r++, c, " Backspace"); - - mvwaddstr(win_help, r++, c, "Save:"); - mvwprintw(win_help, r++, c, " %c", 's'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - -static void show_help_cheat (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c++, "Move:"); - /* hjkl */ - mvwaddch(win_help, r, c, 'h'); - c += 2; - mvwaddch(win_help, r, c, 'j'); - c += 2; - mvwaddch(win_help, r, c, 'k'); - c += 2; - mvwaddch(win_help, r, c, 'l'); - /* Arrows */ - r++; - c = 1; - mvwaddch(win_help, r, c, ACS_LARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_DARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_UARROW); - c += 2; - mvwaddch(win_help, r, c, ACS_RARROW); - - r++; - c = 0; - mvwaddstr(win_help, r++, c, "Cursor:"); - mvwprintw(win_help, r++, c, " %c", 'c'); - - mvwaddstr(win_help, r++, c, "Step:"); - mvwprintw(win_help, r++, c, " Enter / %c", '+'); - - mvwaddstr(win_help, r++, c, "Flag:"); - mvwprintw(win_help, r++, c, " Space"); - - mvwaddstr(win_help, r++, c, "Possible:"); - mvwprintw(win_help, r++, c, " %c", 'f'); - - mvwaddstr(win_help, r++, c, "rm flag:"); - mvwprintw(win_help, r++, c, " Backspace"); - - mvwaddstr(win_help, r++, c, "Save:"); - mvwprintw(win_help, r++, c, " %c", 's'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - -static void show_help_safe (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c, "Save:"); - mvwprintw(win_help, r++, c, " %c", 's'); - - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - -static void show_help_gameover (void) -{ - int r; - int c; - - r = 0; - c = 0; - mvwaddstr(win_help, r++, c, "Quit:"); - mvwprintw(win_help, r++, c, " %c", 'q'); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/player/tmp/Makefile b/modules/player/tmp/Makefile deleted file mode 100644 index bd3c714..0000000 --- a/modules/player/tmp/Makefile +++ /dev/null @@ -1,102 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -GAME_INC_DIR = $(GAME_DIR)/inc/ -MENU_INC_DIR = $(MENU_DIR)/inc/ - -INC_DIR = $(PLAY_DIR)/inc/ -SRC_DIR = $(PLAY_DIR)/src/ - -# dependencies - -_ALL = player_iface.o player_clui.o player_tui.o player_gui.o -ALL = $(_ALL) player_mod.o - -PLAYI_INC_GAME = game_iface.h -PLAYI_INC = player_iface.h player_clui.h player_tui.h player_gui.h -PLAYI_DEPS = $(SRC_DIR)/player_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(PLAYI_INC)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(PLAYI_INC_GAME)) -PLAYI_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) - -PLAYCLUI_INC_GAME = game_iface.h -PLAYCLUI_INC = player_clui.h player_iface.h -PLAYCLUI_DEPS = $(SRC_DIR)/player_clui.c \ - $(patsubst %,$(INC_DIR)/%,$(PLAYCLUI_INC)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(PLAYCLUI_INC_GAME)) -PLAYCLUI_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) - -PLAYTUI_INC_LIBALX = libalx/curses/alx_ncur.h -PLAYTUI_INC_GAME = game_iface.h -PLAYTUI_INC = player_tui.h player_iface.h -PLAYTUI_DEPS = $(SRC_DIR)/player_tui.c \ - $(patsubst %,$(INC_DIR)/%,$(PLAYTUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PLAYTUI_INC_LIBALX)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(PLAYTUI_INC_GAME)) -PLAYTUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(GAME_INC_DIR) - -PLAYGUI_INC_LIBALX = libalx/io/alx_input.h -PLAYGUI_INC_GAME = game_iface.h -PLAYGUI_INC_MENU = menu_gui.h -PLAYGUI_INC = player_gui.h player_iface.h -PLAYGUI_DEPS = $(SRC_DIR)/player_gui.c \ - $(patsubst %,$(INC_DIR)/%,$(PLAYGUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PLAYGUI_INC_LIBALX)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(PLAYGUI_INC_GAME)) \ - $(patsubst %,$(MENU_INC_DIR)/%,$(PLAYGUI_INC_MENU)) -PLAYGUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(MENU_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -player_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -player_iface.s: $(PLAYI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(PLAYI_INC_DIRS) -S $< -o $@ -player_iface.o: player_iface.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -player_clui.s: $(PLAYCLUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(PLAYCLUI_INC_DIRS) -S $< -o $@ -player_clui.o: player_clui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -player_tui.s: $(PLAYTUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(PLAYTUI_INC_DIRS) -S $< -o $@ -player_tui.o: player_tui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -player_gui.s: $(PLAYGUI_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(PLAYGUI_INC_DIRS) -S $< -o $@ -player_gui.o: player_gui.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/save/Makefile b/modules/save/Makefile deleted file mode 100644 index 614a58c..0000000 --- a/modules/save/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(SAVE_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h deleted file mode 100644 index d2dee37..0000000 --- a/modules/save/inc/save.h +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_SAVE_H - # define MSW_SAVE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* bool */ - #include - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # if defined (OS_LINUX) - # define ENV_HOME "HOME" - # elif defined (OS_WIN) - # define ENV_HOME "USERPROFILE" - # endif - - # define USER_GAME_DIR ".mine-sweeper/" - # define USER_SAVED_DIR ".mine-sweeper/saved/" - # define SAVED_NAME_DEFAULT "saved" - # define FILE_EXTENSION ".mine" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char home_path [FILENAME_MAX]; -extern char user_game_path [FILENAME_MAX]; -extern char saved_path [FILENAME_MAX]; -extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void save_init (void); -void save_clr (void); -void load_game_file (void); -void save_game_file (char *filepath); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/inc/score.h b/modules/save/inc/score.h deleted file mode 100644 index fede1f7..0000000 --- a/modules/save/inc/score.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_SCORE_H - # define MSW_SCORE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # if defined (OS_LINUX) - # define ENV_HOME "HOME" - # elif defined (OS_WIN) - # define ENV_HOME "USERPROFILE" - # endif - - # define HISCORES_DIR "hiscores/" - # define BOARDS_BEGINNER_DIR "hiscores/boards_beginner/" - # define BOARDS_INTERMEDIATE_DIR "hiscores/boards_intermediate/" - # define BOARDS_EXPERT_DIR "hiscores/boards_expert/" - # define BOARDS_CUSTOM_DIR "hiscores/boards_custom/" - # define HISCORES_BEGINNER_NAME "hiscores_beginner.mine" - # define HISCORES_INTERMEDIATE_NAME "hiscores_intermediate.mine" - # define HISCORES_EXPERT_NAME "hiscores_expert.mine" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char var_path [FILENAME_MAX]; -extern char var_hiscores_path [FILENAME_MAX]; -extern char var_boards_beginner_path [FILENAME_MAX]; -extern char var_boards_intermediate_path [FILENAME_MAX]; -extern char var_boards_expert_path [FILENAME_MAX]; -extern char var_boards_custom_path [FILENAME_MAX]; - -extern char var_hiscores_beginner_name [FILENAME_MAX]; -extern char var_hiscores_intermediate_name [FILENAME_MAX]; -extern char var_hiscores_expert_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void score_init (void); -void save_score (const struct Game_Iface_Score *game_iface_score); -void snprint_scores (char *dest, int destsize); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* score.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/src/save.c b/modules/save/src/save.c deleted file mode 100644 index d1245e0..0000000 --- a/modules/save/src/save.c +++ /dev/null @@ -1,255 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - #include - #include - #include - - /* mkdir */ - #include - - #include "game.h" - #include "player_iface.h" - - #include "save.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - char home_path [FILENAME_MAX]; - char user_game_path [FILENAME_MAX]; - char saved_path [FILENAME_MAX]; - char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void save_init (void) -{ - - if (snprintf(home_path, FILENAME_MAX, "%s/", - getenv(ENV_HOME)) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(user_game_path, FILENAME_MAX, "%s/%s/", - home_path, USER_GAME_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; - } - saved_name[0] = '\0'; - - if (mkdir(user_game_path, 0700)) { - switch (errno) { - case EACCES: - printf("err = EACCES"); - exit(EXIT_FAILURE); - case EEXIST: - /* OK */ - return; - default: - printf("WTF?!"); - exit(EXIT_FAILURE); - } - } - if (mkdir(saved_path, 0700)) { - switch (errno) { - case EACCES: - printf("err = EACCES"); - exit(EXIT_FAILURE); - case EEXIST: - /* OK */ - return; - default: - printf("WTF?!"); - exit(EXIT_FAILURE); - } - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - getchar(); - exit(EXIT_FAILURE); -} - -void save_clr (void) -{ - - if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - getchar(); - exit(EXIT_FAILURE); -} - -void load_game_file (void) -{ - char file_name [FILENAME_MAX]; - FILE *fp; - int i; - int j; - - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - saved_path, saved_name) >= FILENAME_MAX) { - goto err_path; - } - - fp = fopen(file_name, "r"); - if (fp) { - fscanf(fp, "mine-sweeper saved game"); - fscanf(fp, " rows %i", &game_board.rows); - fscanf(fp, " cols %i", &game_board.cols); - fscanf(fp, " mines %i", &game_board.mines); - fscanf(fp, " gnd"); - for (i = 0; i < game_board.rows; i++) { - fscanf(fp, " %i", &game_board.gnd[i][0]); - for (j = 1; j < game_board.cols; j++) - fscanf(fp, ",%i", &game_board.gnd[i][j]); - } - fscanf(fp, " usr"); - for (i = 0; i < game_board.rows; i++) { - fscanf(fp, " %i", &game_board.usr[i][0]); - for (j = 1; j < game_board.cols; j++) - fscanf(fp, ",%i", &game_board.usr[i][j]); - } - fscanf(fp, " flags %i", &game_board.flags); - fscanf(fp, " cleared %i", &game_board.clr); - - fclose(fp); - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - getchar(); - exit(EXIT_FAILURE); -} - -void save_game_file (char *filepath) -{ - char file_name [FILENAME_MAX]; - char tmp [FILENAME_MAX]; - char old_saved [FILENAME_MAX]; - char file_num [6]; - FILE *fp; - int i; - int j; - bool x; - - /* Don't change saved_name variable if not in default dir */ - if (filepath) - snprintf(old_saved, FILENAME_MAX, "%s", saved_name); - - /* Default path & name */ - save_clr(); - snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); - file_num[0] = '\0'; - - /* Request file name */ - player_iface_save_name(filepath, saved_name, FILENAME_MAX); - - /* Look for an unused name of the type 'name_XXX.mine'. */ - x = true; - for (i = 0; x; i++) { - if (filepath == NULL) { - if (snprintf(file_name, FILENAME_MAX, "%s/%s%s%s", - saved_path, - saved_name, file_num, - FILE_EXTENSION) >= FILENAME_MAX) { - goto err_path; - } - } else { - if (snprintf(file_name, FILENAME_MAX, "%s/%s%s%s", - filepath, - saved_name, file_num, - FILE_EXTENSION) >= FILENAME_MAX) { - goto err_path; - } - } - - fp = fopen(file_name, "r"); - if (fp) { - fclose(fp); - file_num[0] = '_'; - file_num[1] = '0' + ((i / 100) % 10); - file_num[2] = '0' + ((i / 10) % 10); - file_num[3] = '0' + (i % 10); - file_num[4] = '\0'; - } else { - x = false; - if (snprintf(tmp, FILENAME_MAX, "%s%s%s", - saved_name, file_num, - FILE_EXTENSION) >= FILENAME_MAX) { - goto err_path; - } - snprintf(saved_name, FILENAME_MAX, "%s", tmp); - } - } - - /* Write to a new file */ - fp = fopen(file_name, "w"); - if (fp) { - fprintf(fp, "mine-sweeper saved game\n"); - fprintf(fp, "rows %i\n", game_board.rows); - fprintf(fp, "cols %i\n", game_board.cols); - fprintf(fp, "mines %i\n", game_board.mines); - fprintf(fp, "gnd\n"); - for (i = 0; i < game_board.rows; i++) { - fprintf(fp, "%i", game_board.gnd[i][0]); - for (j = 1; j < game_board.cols; j++) - fprintf(fp, ",%i", game_board.gnd[i][j]); - fprintf(fp, "\n"); - } - fprintf(fp, "usr\n"); - for (i = 0; i < game_board.rows; i++) { - fprintf(fp, "%i", game_board.usr[i][0]); - for (j = 1; j < game_board.cols; j++) - fprintf(fp, ",%i", game_board.usr[i][j]); - fprintf(fp, "\n"); - } - fprintf(fp, "flags %i\n", game_board.flags); - fprintf(fp, "cleared %i\n", game_board.clr); - - fclose(fp); - } - - /* Don't change saved_name if saving in non-default dir */ - if (filepath) - snprintf(saved_name, FILENAME_MAX, "%s", old_saved); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - getchar(); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/src/score.c b/modules/save/src/score.c deleted file mode 100644 index 21f7602..0000000 --- a/modules/save/src/score.c +++ /dev/null @@ -1,311 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include - #include - #include -/* Project -------------------------------------------------------------------*/ - #include "game.h" - #include "game_iface.h" - #include "player_iface.h" - - #include "save.h" - - #include "score.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - # define BUFF_SIZE_TEXT (1048576) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - char var_path [FILENAME_MAX]; - char var_hiscores_path [FILENAME_MAX]; - char var_boards_beginner_path [FILENAME_MAX]; - char var_boards_intermediate_path [FILENAME_MAX]; - char var_boards_expert_path [FILENAME_MAX]; - char var_boards_custom_path [FILENAME_MAX]; - - char var_hiscores_beginner_name [FILENAME_MAX]; - char var_hiscores_intermediate_name [FILENAME_MAX]; - char var_hiscores_expert_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void snprint_scores_file (char *dest, int destsize, char *file_name); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void score_init (void) -{ - - if (snprintf(var_path, FILENAME_MAX, "%s/%s/", - INSTALL_VAR_DIR, VAR_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(var_hiscores_path, FILENAME_MAX, "%s/%s/", - var_path, HISCORES_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(var_boards_beginner_path, FILENAME_MAX, "%s/%s/", - var_path, BOARDS_BEGINNER_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(var_boards_intermediate_path, FILENAME_MAX, "%s/%s/", - var_path, BOARDS_INTERMEDIATE_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(var_boards_expert_path, FILENAME_MAX, "%s/%s/", - var_path, BOARDS_EXPERT_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(var_boards_custom_path, FILENAME_MAX, "%s/%s/", - var_path, BOARDS_CUSTOM_DIR) >= FILENAME_MAX) { - goto err_path; - } - snprintf(var_hiscores_beginner_name, FILENAME_MAX, "%s", - HISCORES_BEGINNER_NAME); - snprintf(var_hiscores_intermediate_name, FILENAME_MAX, "%s", - HISCORES_INTERMEDIATE_NAME); - snprintf(var_hiscores_expert_name, FILENAME_MAX, "%s", - HISCORES_EXPERT_NAME); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - getchar(); - exit(EXIT_FAILURE); -} - -void save_score (const struct Game_Iface_Score *game_iface_score) -{ - struct tm *date_format; - char file_name [FILENAME_MAX]; - char player_name [BUFF_SIZE]; - FILE *fp; - time_t date_secs; - - /* File name */ - switch (game_iface_score->level) { - case GAME_IFACE_LEVEL_BEGINNER: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_beginner_name) >= - FILENAME_MAX) { - goto err_path; - } - break; - - case GAME_IFACE_LEVEL_INTERMEDIATE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_intermediate_name) >= - FILENAME_MAX) { - goto err_path; - } - break; - - case GAME_IFACE_LEVEL_EXPERT: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_expert_name) >= - FILENAME_MAX) { - goto err_path; - } - break; - } - - /* Date & time */ - date_secs = time(NULL); - date_format = localtime(&date_secs); - - /* Player name (foo is default) */ - player_iface_score_name(player_name, BUFF_SIZE); - - /* Write to file (append) */ - errno = 0; - fp = fopen(file_name, "a"); - if (!fp) - goto err_fp; - fprintf(fp, "\n"); - fprintf(fp, "name %s\n", player_name); - fprintf(fp, "date %i\n", (int)date_secs); - fprintf(fp, "{\n"); - fprintf(fp, " isdst %i\n", date_format->tm_isdst); - fprintf(fp, " yday %i\n", date_format->tm_yday); - fprintf(fp, " wday %i\n", date_format->tm_wday); - fprintf(fp, " year %i\n", date_format->tm_year); - fprintf(fp, " mon %i\n", date_format->tm_mon); - fprintf(fp, " mday %i\n", date_format->tm_mday); - fprintf(fp, " hour %i\n", date_format->tm_hour); - fprintf(fp, " min %i\n", date_format->tm_min); - fprintf(fp, " sec %i\n", date_format->tm_sec); - fprintf(fp, "}\n"); - fprintf(fp, "time %i\n", game_iface_score->time); - fprintf(fp, "clicks %i\n", game_iface_score->clicks); - fprintf(fp, "file %s\n", saved_name); - fclose(fp); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - printf("Score could not be saved!\n"); - return; - -err_fp: - printf("errno: %i", errno); - printf("Score could not be saved!\n"); - return; -} - -void snprint_scores (char *dest, int destsize) -{ - char file_name [FILENAME_MAX]; - char tmp1 [BUFF_SIZE_TEXT]; - char tmp2 [BUFF_SIZE_TEXT]; - - /* Beginner */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_beginner_name) >= - FILENAME_MAX) { - goto err_path; - } - (void)snprint_scores_file(dest, destsize, file_name); - - /* Intermediate */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_intermediate_name) >= - FILENAME_MAX) { - goto err_path; - } - (void)snprint_scores_file(tmp1, destsize, file_name); - (void)snprintf(tmp2, destsize, "%s%s", dest, tmp1); - (void)snprintf(dest, destsize, "%s", tmp2); - - /* Expert */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - var_hiscores_path, - var_hiscores_expert_name) >= - FILENAME_MAX) { - goto err_path; - } - (void)snprint_scores_file(tmp1, destsize, file_name); - (void)snprintf(tmp2, destsize, "%s%s", dest, tmp1); - (void)snprintf(dest, destsize, "%s", tmp2); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - printf("Score could not be shown!\n"); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void snprint_scores_file (char *dest, int destsize, char *file_name) -{ - FILE *fp; - int c; - char tmp [BUFF_SIZE_TEXT]; - char title [BUFF_SIZE]; - char name [BUFF_SIZE]; - int year; - int mon; - int day; - int time; - int hours; - int mins; - int secs; - int clicks; - char file [FILENAME_MAX]; - - fp = fopen(file_name, "r"); - if (!fp) - return; - - /* Title */ - fscanf(fp, "%[^\n]s", title); - /* For some reason, a space after "%[^\n]s" doesn't skip spaces */ - fscanf(fp, " "); - - /* Print */ - (void)snprintf(dest, destsize, - "_______________________________________________________\n" - "%s\n\n" - "name date clicks time file\n\n", - title); - - while ((c = getc(fp)) != EOF) { - ungetc(c, fp); - - /* Read */ - fscanf(fp, "name %s ", name); - fscanf(fp, "date %*i "); - fscanf(fp, "{ "); - fscanf(fp, " isdst %*i "); - fscanf(fp, " yday %*i "); - fscanf(fp, " wday %*i "); - fscanf(fp, " year %i ", &year); - fscanf(fp, " mon %i ", &mon); - fscanf(fp, " mday %i ", &day); - fscanf(fp, " hour %*i "); - fscanf(fp, " min %*i "); - fscanf(fp, " sec %*i "); - fscanf(fp, "} "); - fscanf(fp, "time %i ", &time); - fscanf(fp, "clicks %i ", &clicks); - fscanf(fp, "file %s ", file); - - /* Adjust date & time */ - year += 1900; - hours = (time / 3600); - mins = ((time % 3600) / 60); - secs = (time % 60); - - /* Print */ - (void)snprintf(tmp, BUFF_SIZE_TEXT, - "%s" - "%s\n" - " %4i/%2i/%2i %i %i:%02i:%02i \t%s\n\n", - dest, - name, - year, 1 + mon, day, - clicks, - hours, mins, secs, - file); - (void)snprintf(dest, BUFF_SIZE_TEXT, "%s", tmp); - } - - fclose(fp); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile deleted file mode 100644 index c096cb0..0000000 --- a/modules/save/tmp/Makefile +++ /dev/null @@ -1,67 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -GAME_INC_DIR = $(GAME_DIR)/inc/ -PLAY_INC_DIR = $(PLAY_DIR)/inc/ - -INC_DIR = $(SAVE_DIR)/inc/ -SRC_DIR = $(SAVE_DIR)/src/ - -# dependencies - -_ALL = save.o score.o -ALL = $(_ALL) save_mod.o - -SAVE_INC_PLAY = player_iface.h -SAVE_INC_GAME = game.h -SAVE_INC = save.h -SAVE_DEPS = $(SRC_DIR)/save.c \ - $(patsubst %,$(INC_DIR)/%,$(SAVE_INC)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(SAVE_INC_GAME)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(SAVE_INC_PLAY)) -SAVE_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(PLAY_INC_DIR) - -SCORE_INC_PLAY = player_iface.h -SCORE_INC_GAME = game.h game_iface.h -SCORE_INC = score.h -SCORE_DEPS = $(SRC_DIR)/score.c \ - $(patsubst %,$(INC_DIR)/%,$(SCORE_INC)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(SCORE_INC_GAME)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(SCORE_INC_PLAY)) -SCORE_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(PLAY_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -save_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -save.s: $(SAVE_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(SAVE_INC_DIRS) -S $< -o $@ -save.o: save.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -score.s: $(SCORE_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(SCORE_INC_DIRS) -S $< -o $@ -score.o: score.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/tmp/Makefile b/modules/tmp/Makefile deleted file mode 100644 index 3cf4748..0000000 --- a/modules/tmp/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -ABOUT_TMP_DIR = $(ABOUT_DIR)/tmp/ -CTRL_TMP_DIR = $(CTRL_DIR)/tmp/ -GAME_TMP_DIR = $(GAME_DIR)/tmp/ -MENU_TMP_DIR = $(MENU_DIR)/tmp/ -PLAY_TMP_DIR = $(PLAY_DIR)/tmp/ -SAVE_TMP_DIR = $(SAVE_DIR)/tmp/ -XYZZY_TMP_DIR = $(XYZZY_DIR)/tmp/ - -# dependencies - -ALL = modules.o - -MODS_OBJ_ABOUT = about_mod.o -MODS_OBJ_CTRL = ctrl_mod.o -MODS_OBJ_GAME = game_mod.o -MODS_OBJ_MENU = menu_mod.o -MODS_OBJ_PLAY = player_mod.o -MODS_OBJ_SAVE = save_mod.o -MODS_OBJ_XYZZY = xyzzy_mod.o -MODS_OBJS = $(patsubst %,$(ABOUT_TMP_DIR)/%,$(MODS_OBJ_ABOUT)) \ - $(patsubst %,$(CTRL_TMP_DIR)/%,$(MODS_OBJ_CTRL)) \ - $(patsubst %,$(GAME_TMP_DIR)/%,$(MODS_OBJ_GAME)) \ - $(patsubst %,$(MENU_TMP_DIR)/%,$(MODS_OBJ_MENU)) \ - $(patsubst %,$(PLAY_TMP_DIR)/%,$(MODS_OBJ_PLAY)) \ - $(patsubst %,$(SAVE_TMP_DIR)/%,$(MODS_OBJ_SAVE)) \ - $(patsubst %,$(XYZZY_TMP_DIR)/%,$(MODS_OBJ_XYZZY)) - -# target: dependencies -# action - -all: $(ALL) - - -modules.o: $(MODS_OBJS) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -clean: - $(Q)rm -f *.o diff --git a/modules/xyzzy/Makefile b/modules/xyzzy/Makefile deleted file mode 100644 index 8cc4244..0000000 --- a/modules/xyzzy/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(XYZZY_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/xyzzy/inc/xyzzy.h b/modules/xyzzy/inc/xyzzy.h deleted file mode 100644 index e81d5e9..0000000 --- a/modules/xyzzy/inc/xyzzy.h +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef MSW_XYZZY_H - # define MSW_XYZZY_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void xyzzy_init (void); -int xyzzy_lin (const struct Game_Iface_Out *out, - struct Game_Iface_In *in); -int xyzzy_p (const struct Game_Iface_Out *out, - struct Game_Iface_In *in); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* xyzzy.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/xyzzy/src/xyzzy.c b/modules/xyzzy/src/xyzzy.c deleted file mode 100644 index 4e0cb66..0000000 --- a/modules/xyzzy/src/xyzzy.c +++ /dev/null @@ -1,108 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include - - #include "game_iface.h" - - #include "xyzzy.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -static int x; -static bool step_notflag; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void xyzzy_step_all (const struct Game_Iface_Out *out, - struct Game_Iface_In *in); -static void xyzzy_flag_all (const struct Game_Iface_Out *out, - struct Game_Iface_In *in); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void xyzzy_init (void) -{ - - x = 0; - step_notflag = true; -} - -int xyzzy_lin (const struct Game_Iface_Out *out, - struct Game_Iface_In *in) -{ - - if (!x) - x = 1; - - if (step_notflag) { - xyzzy_step_all(out, in); - } else { - xyzzy_flag_all(out, in); - x--; - } - - step_notflag = !step_notflag; - - return x; -} - -int xyzzy_p (const struct Game_Iface_Out *out, - struct Game_Iface_In *in) -{ - - if (!x) - x = (out->rows * out->cols) / 2; - - xyzzy_lin(out, in); - - return x; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void xyzzy_step_all (const struct Game_Iface_Out *out, - struct Game_Iface_In *in) -{ - int i; - int j; - - for (i = 0; i < out->rows; i++) { - for (j = 0; j < out->cols; j++) { - if (out->usr[i][j] == GAME_IFACE_USR_CLEAR) - in->act_game[i][j] = GAME_IFACE_GAME_ACT_STEP; - } - } -} - -static void xyzzy_flag_all (const struct Game_Iface_Out *out, - struct Game_Iface_In *in) -{ - int i; - int j; - - for (i = 0; i < out->rows; i++) { - for (j = 0; j < out->cols; j++) { - if (out->usr[i][j] == GAME_IFACE_USR_CLEAR) - in->act_game[i][j] = GAME_IFACE_GAME_ACT_FLAG; - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/xyzzy/tmp/Makefile b/modules/xyzzy/tmp/Makefile deleted file mode 100644 index dc82625..0000000 --- a/modules/xyzzy/tmp/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -GAME_INC_DIR = $(GAME_DIR)/inc/ - -INC_DIR = $(XYZZY_DIR)/inc/ -SRC_DIR = $(XYZZY_DIR)/src/ - -# dependencies - -_ALL = xyzzy.o -ALL = $(_ALL) xyzzy_mod.o - -XYZZY_INC_GAME = game_iface.h -XYZZY_INC = xyzzy.h -XYZZY_DEPS = $(SRC_DIR)/xyzzy.c \ - $(patsubst %,$(INC_DIR)/%,$(XYZZY_INC)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(XYZZY_INC_GAME)) -XYZZY_INC_DIRS = -I $(INC_DIR) \ - -I $(GAME_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -xyzzy_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -xyzzy.s: $(XYZZY_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(XYZZY_INC_DIRS) -S $< -o $@ -xyzzy.o: xyzzy.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s diff --git a/share/COPYRIGHT.txt b/share/COPYRIGHT.txt deleted file mode 100644 index f4b79da..0000000 --- a/share/COPYRIGHT.txt +++ /dev/null @@ -1,15 +0,0 @@ - - - Based on the game 'Mine', written in 1990 by - Robert Donner & Curt Johnson at Duff Software. - - Check this: https://tcrf.net/Proto:Minesweeper_(Windows,_1990) - - ---------------------------------------------------------------- - - mine-sweeper Copyright (C) 2015 Alejandro COLOMAR ANDRES - - This program comes with ABSOLUTELY NO WARRANTY. - This is free software, and you are welcome to redistribute it - under certain conditions; see the file COPYING.txt for details. - diff --git a/share/DISCLAIMER.txt b/share/DISCLAIMER.txt deleted file mode 100644 index 291440a..0000000 --- a/share/DISCLAIMER.txt +++ /dev/null @@ -1,16 +0,0 @@ -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - Disclaimer of Warranty. - -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. - -THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OFANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - -THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. - -SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY -SERVICING, REPAIR OR CORRECTION. - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/share/HELP.txt b/share/HELP.txt deleted file mode 100644 index 3f66acb..0000000 --- a/share/HELP.txt +++ /dev/null @@ -1,41 +0,0 @@ -Usage: $ mine-sweeper [OPTION...] - - -a, --rows=ROWS set number of rows - -b, --columns=COLS set number of columns - -f, --file=FILE set game file - -i, --iface=IFACE set game interface - -p, --proportion=PROPORTION set proportion of mines - - Main modes of operation: - -s, --start=START_MODE set start mode - -x, --exit exit after using command line options - (don't start menu) - - Controlling formatted output: - -V, --verbose=LEVEL set verbose level - - Other: - -L, --license display license - -h, --help give this help list - -u, --usage give a short usage message - -v, --version print program version - - Only for DEVEL (disabled in normal release): - -r, --rand-seed=SEED set seed for rand (DEVEL; DISABLED) - -MANDATORY or [OPTIONAL] arguments to long options are also mandatory or optional -for any corresponding short options. - - - Examples: - $ mine-sweeper - $ mine-sweeper --version - $ mine-sweeper --license - $ mine-sweeper -i 1 - $ mine-sweeper -a 5 -b 15 -p 0.1 - $ mine-sweeper -a 15 -b 20 -p 0.3 -s 1 -x - $ mine-sweeper -f ../files/saved/saved_000.mine -s 2 -x - - -Report bugs to: 1903716@gmail.com -mine-sweeper home page: diff --git a/share/LICENSE.txt b/share/LICENSE.txt deleted file mode 100644 index 81c77e6..0000000 --- a/share/LICENSE.txt +++ /dev/null @@ -1,352 +0,0 @@ - NOTE! The GPL below is copyrighted by the Free Software - Foundation, but the instance of code that it refers to (mine-sweeper) - is copyrighted by me who actually wrote it. - - Also note that the only valid version of the GPL is _this_ particular - version of the license (ie v2, not v2.2 or v3.x or whatever), unless - explicitly otherwise stated. - - Alejandro Colomar - ----------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/share/README.txt b/share/README.txt deleted file mode 100644 index c399fe2..0000000 --- a/share/README.txt +++ /dev/null @@ -1,119 +0,0 @@ -/****************************************************************************** - * Based on the game 'Mine', written in 1990 by * - * Robert Donner & Curt Johnson at Duff Software. * - * * - * Check this: https://tcrf.net/Proto:Minesweeper_(Windows,_1990) * - ****************************************************************************** - * mine-sweeper Copyright (C) 2015 Alejandro Colomar Andrés * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see the file COPYING, or write * - * to the Free Software Foundation, Inc. * - ****************************************************************************** - * Disclaimer of Warranty. * - * * - * THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY * - * APPLICABLE LAW. * - * * - * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER * - * PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * - * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * * - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH * - * YOU. * - * * - * SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY * - * SERVICING, REPAIR OR CORRECTION. * - ******************************************************************************/ - - If you make a version, please tell me. - I would like to see it. Thank you. - -site: - https://github.com/AlejandroColomar/mine-sweeper - - -COMPILE: - - linux: - $ make - - windows (MSYS2): - $ make OS=win - -INSTALL: - - linux: - # make install - - windows: - run 'SETUP.cmd' as administrator - -RUN: - - linux: - $ mine-sweeper - if it doesn't work: - $ /usr/local/games/mine-sweeper - - windows: - run 'bin/mine-sweeper.exe' - -UNINSTALL: - - linux: - # make uninstall - - windows: - run 'UNINSTALL.cmd' as administrator - - -The program creates a folder '.mine-sweeper/' at $HOME (also in Windows). It -is used by the program to store saved games. If you remove the game, you -should delete that folder manually. - - -THE PROGRAM DOES: - The typical minesweeper game. - - -MENU: - When you run the program, it starts in a menu that has these branches: - - /* - * + Menu: - * + Continue: - * - Start - * + Select map: - * - New map - * - Load map(File: "") - * - .. - * + Change difficulty: - * - Beginner - * - Intermediate - * - Expert - * + Custom: - * - Change rows: rows (X) - * - Change columns: cols (X) - * - Change proportion of mines: p (0.XXXXXX) - * - .. - * - .. - * - Change file name (File: "") - * - Hi scores - * N/A x DEVEL: - * N/A - Change seed (srand) - * N/A - .. - * - .. - * - Disclaimer of warranty - * - Terms and conditions - * - Exit program - */ - - -SYSTEM REQUIREMENTS: - - * A terminal ¿? - -To be continued... diff --git a/share/USAGE.txt b/share/USAGE.txt deleted file mode 100644 index 043fe24..0000000 --- a/share/USAGE.txt +++ /dev/null @@ -1,8 +0,0 @@ - Usage: $ mine-sweeper [--exit] [--help] [--license] [--usage] - [--verbose=LEVEL] [--version] - [--rows=ROWS] [--columns=COLS] [--file=FILE] - [--iface=IFACE] [--proportion=PROPORTION] - [--start=START_MODE] - - - Type '$ mine-sweeper --help' for a full description. diff --git a/share/mine-sweeper/COPYRIGHT.txt b/share/mine-sweeper/COPYRIGHT.txt new file mode 100755 index 0000000..f4b79da --- /dev/null +++ b/share/mine-sweeper/COPYRIGHT.txt @@ -0,0 +1,15 @@ + + + Based on the game 'Mine', written in 1990 by + Robert Donner & Curt Johnson at Duff Software. + + Check this: https://tcrf.net/Proto:Minesweeper_(Windows,_1990) + + ---------------------------------------------------------------- + + mine-sweeper Copyright (C) 2015 Alejandro COLOMAR ANDRES + + This program comes with ABSOLUTELY NO WARRANTY. + This is free software, and you are welcome to redistribute it + under certain conditions; see the file COPYING.txt for details. + diff --git a/share/mine-sweeper/DISCLAIMER.txt b/share/mine-sweeper/DISCLAIMER.txt new file mode 100755 index 0000000..291440a --- /dev/null +++ b/share/mine-sweeper/DISCLAIMER.txt @@ -0,0 +1,16 @@ +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. + +THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OFANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. + +SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY +SERVICING, REPAIR OR CORRECTION. + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/share/mine-sweeper/HELP.txt b/share/mine-sweeper/HELP.txt new file mode 100755 index 0000000..3f66acb --- /dev/null +++ b/share/mine-sweeper/HELP.txt @@ -0,0 +1,41 @@ +Usage: $ mine-sweeper [OPTION...] + + -a, --rows=ROWS set number of rows + -b, --columns=COLS set number of columns + -f, --file=FILE set game file + -i, --iface=IFACE set game interface + -p, --proportion=PROPORTION set proportion of mines + + Main modes of operation: + -s, --start=START_MODE set start mode + -x, --exit exit after using command line options + (don't start menu) + + Controlling formatted output: + -V, --verbose=LEVEL set verbose level + + Other: + -L, --license display license + -h, --help give this help list + -u, --usage give a short usage message + -v, --version print program version + + Only for DEVEL (disabled in normal release): + -r, --rand-seed=SEED set seed for rand (DEVEL; DISABLED) + +MANDATORY or [OPTIONAL] arguments to long options are also mandatory or optional +for any corresponding short options. + + + Examples: + $ mine-sweeper + $ mine-sweeper --version + $ mine-sweeper --license + $ mine-sweeper -i 1 + $ mine-sweeper -a 5 -b 15 -p 0.1 + $ mine-sweeper -a 15 -b 20 -p 0.3 -s 1 -x + $ mine-sweeper -f ../files/saved/saved_000.mine -s 2 -x + + +Report bugs to: 1903716@gmail.com +mine-sweeper home page: diff --git a/share/mine-sweeper/LICENSE.txt b/share/mine-sweeper/LICENSE.txt new file mode 100755 index 0000000..81c77e6 --- /dev/null +++ b/share/mine-sweeper/LICENSE.txt @@ -0,0 +1,352 @@ + NOTE! The GPL below is copyrighted by the Free Software + Foundation, but the instance of code that it refers to (mine-sweeper) + is copyrighted by me who actually wrote it. + + Also note that the only valid version of the GPL is _this_ particular + version of the license (ie v2, not v2.2 or v3.x or whatever), unless + explicitly otherwise stated. + + Alejandro Colomar + +---------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/share/mine-sweeper/README.txt b/share/mine-sweeper/README.txt new file mode 100755 index 0000000..c399fe2 --- /dev/null +++ b/share/mine-sweeper/README.txt @@ -0,0 +1,119 @@ +/****************************************************************************** + * Based on the game 'Mine', written in 1990 by * + * Robert Donner & Curt Johnson at Duff Software. * + * * + * Check this: https://tcrf.net/Proto:Minesweeper_(Windows,_1990) * + ****************************************************************************** + * mine-sweeper Copyright (C) 2015 Alejandro Colomar Andrés * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see the file COPYING, or write * + * to the Free Software Foundation, Inc. * + ****************************************************************************** + * Disclaimer of Warranty. * + * * + * THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY * + * APPLICABLE LAW. * + * * + * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER * + * PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * + * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * * + * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH * + * YOU. * + * * + * SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY * + * SERVICING, REPAIR OR CORRECTION. * + ******************************************************************************/ + + If you make a version, please tell me. + I would like to see it. Thank you. + +site: + https://github.com/AlejandroColomar/mine-sweeper + + +COMPILE: + - linux: + $ make + - windows (MSYS2): + $ make OS=win + +INSTALL: + - linux: + # make install + - windows: + run 'SETUP.cmd' as administrator + +RUN: + - linux: + $ mine-sweeper + if it doesn't work: + $ /usr/local/games/mine-sweeper + - windows: + run 'bin/mine-sweeper.exe' + +UNINSTALL: + - linux: + # make uninstall + - windows: + run 'UNINSTALL.cmd' as administrator + + +The program creates a folder '.mine-sweeper/' at $HOME (also in Windows). It +is used by the program to store saved games. If you remove the game, you +should delete that folder manually. + + +THE PROGRAM DOES: + The typical minesweeper game. + + +MENU: + When you run the program, it starts in a menu that has these branches: + + /* + * + Menu: + * + Continue: + * - Start + * + Select map: + * - New map + * - Load map(File: "") + * - .. + * + Change difficulty: + * - Beginner + * - Intermediate + * - Expert + * + Custom: + * - Change rows: rows (X) + * - Change columns: cols (X) + * - Change proportion of mines: p (0.XXXXXX) + * - .. + * - .. + * - Change file name (File: "") + * - Hi scores + * N/A x DEVEL: + * N/A - Change seed (srand) + * N/A - .. + * - .. + * - Disclaimer of warranty + * - Terms and conditions + * - Exit program + */ + + +SYSTEM REQUIREMENTS: + + * A terminal ¿? + +To be continued... diff --git a/share/mine-sweeper/USAGE.txt b/share/mine-sweeper/USAGE.txt new file mode 100755 index 0000000..043fe24 --- /dev/null +++ b/share/mine-sweeper/USAGE.txt @@ -0,0 +1,8 @@ + Usage: $ mine-sweeper [--exit] [--help] [--license] [--usage] + [--verbose=LEVEL] [--version] + [--rows=ROWS] [--columns=COLS] [--file=FILE] + [--iface=IFACE] [--proportion=PROPORTION] + [--start=START_MODE] + + + Type '$ mine-sweeper --help' for a full description. diff --git a/share/mine-sweeper/saved/saved_000.mine b/share/mine-sweeper/saved/saved_000.mine new file mode 100755 index 0000000..536ccf9 --- /dev/null +++ b/share/mine-sweeper/saved/saved_000.mine @@ -0,0 +1,24 @@ +mine-sweeper saved game +rows 8 +cols 8 +mines 9 +gnd +9,2,9,1,0,0,1,9 +2,4,2,2,0,0,1,1 +9,2,9,1,0,0,1,1 +1,2,1,1,0,0,2,10 +0,0,0,0,0,0,2,10 +0,0,0,0,0,0,1,1 +1,1,0,0,0,0,1,1 +9,1,0,0,0,0,1,9 +usr +2,0,0,1,1,1,1,3 +2,0,0,1,1,1,1,0 +0,0,0,1,1,1,1,0 +1,1,1,1,1,1,1,0 +1,1,1,1,1,1,1,0 +1,1,1,1,1,1,1,0 +1,1,1,1,1,1,1,0 +0,1,1,1,1,1,1,0 +flags 2 +cleared 46 diff --git a/share/saved/saved_000.mine b/share/saved/saved_000.mine deleted file mode 100644 index 536ccf9..0000000 --- a/share/saved/saved_000.mine +++ /dev/null @@ -1,24 +0,0 @@ -mine-sweeper saved game -rows 8 -cols 8 -mines 9 -gnd -9,2,9,1,0,0,1,9 -2,4,2,2,0,0,1,1 -9,2,9,1,0,0,1,1 -1,2,1,1,0,0,2,10 -0,0,0,0,0,0,2,10 -0,0,0,0,0,0,1,1 -1,1,0,0,0,0,1,1 -9,1,0,0,0,0,1,9 -usr -2,0,0,1,1,1,1,3 -2,0,0,1,1,1,1,0 -0,0,0,1,1,1,1,0 -1,1,1,1,1,1,1,0 -1,1,1,1,1,1,1,0 -1,1,1,1,1,1,1,0 -1,1,1,1,1,1,1,0 -0,1,1,1,1,1,1,0 -flags 2 -cleared 46 diff --git a/src/about/about.c b/src/about/about.c new file mode 100755 index 0000000..0d7cee2 --- /dev/null +++ b/src/about/about.c @@ -0,0 +1,95 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/about/about.h" + +#include +#include +#include + +#include "libalx/base/errno/perror.h" +#include "libalx/base/stddef/size.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void print_share_file (int file) +{ + char *fname; + char cmd[_POSIX_ARG_MAX]; + + switch (file) { + case SHARE_COPYRIGHT: + fname = SHARE_COPYRIGHT_FILE; + break; + case SHARE_DISCLAIMER: + fname = SHARE_DISCLAIMER_FILE; + break; + case SHARE_HELP: + fname = SHARE_HELP_FILE; + break; + case SHARE_LICENSE: + fname = SHARE_LICENSE_FILE; + break; + case SHARE_USAGE: + fname = SHARE_USAGE_FILE; + break; + } + + if (snprintf(cmd, sizeof(cmd), "less %s", fname) >= SSIZEOF(cmd)) + goto err; + if (system(cmd)) + alx_perror(NULL); + + return; +err: + alx_perror(cmd); +} + +void print_version (void) +{ + + printf("%s %s\n\n", PROG_NAME, PROG_VERSION); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/ctrl/start.c b/src/ctrl/start.c new file mode 100755 index 0000000..1e62b88 --- /dev/null +++ b/src/ctrl/start.c @@ -0,0 +1,110 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/ctrl/start.h" + +#include +#include +#include +#include + +#include "mine-sweeper/game/core.h" +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/menu/iface.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int start_mode; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void); +static void start_rand (void); +static void start_load (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void start_switch (void) +{ + + switch (start_mode) { + case START_FOO: + start_foo(); + break; + case START_RAND: + start_rand(); + break; + case START_LOAD: + start_load(); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void) +{ +} + +static void start_rand (void) +{ + int level; + ptrdiff_t rows, cols; + int mines; + ptrdiff_t r, c; + + menu_iface_board(&level, &rows, &cols, &mines); + player_iface_init(rows, cols); + if (player_iface_start(&r, &c)) + goto err; + game_init_rand(rows, cols, mines, r, c); + game_iface_init_rand(level, r, c); + + /* game loop */ + game_iface(); + +err: + player_iface_cleanup(); +} + +static void start_load (void) +{ + ptrdiff_t rows, cols; + + /* size & game init (sets errno) */ + errno = 0; + if (game_init_load(&rows, &cols)) + goto err; + + player_iface_init(rows, cols); + game_iface_init_load(); + + /* game loop */ + game_iface(); + + player_iface_cleanup(); + return; + +err: + fprintf(stderr, "%s:%i: %s(): %s", __FILE__, __LINE__, __func__, + strerror(errno)); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/game/core.c b/src/game/core.c new file mode 100755 index 0000000..aa694b7 --- /dev/null +++ b/src/game/core.c @@ -0,0 +1,383 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/game/core.h" + +#include +#include +#include +#include + +#include + +#include "libalx/base/stdlib/seed_mix.h" + +#include "mine-sweeper/save/save.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + struct Game_Board game_board; +/* Static --------------------------------------------------------------------*/ + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Init */ +static void game_init_clr (void); +static void game_init_mines (ptrdiff_t pos_row, ptrdiff_t pos_col); +static void game_init_adjnums (void); + /* Step */ +static void game_step (ptrdiff_t r, ptrdiff_t c); +static void game_discover (ptrdiff_t r, ptrdiff_t c); +static void game_discover_recursive (ptrdiff_t r, ptrdiff_t c); +static void game_big_step (ptrdiff_t r, ptrdiff_t c); +static int game_count_flags (ptrdiff_t r, ptrdiff_t c); +static void game_step_recursive (ptrdiff_t r, ptrdiff_t c); + /* Flag */ +static void game_flag (ptrdiff_t r, ptrdiff_t c); +static void game_possible (ptrdiff_t r, ptrdiff_t c); +static void game_rmflag (ptrdiff_t r, ptrdiff_t c); +static void game_all_flags (ptrdiff_t r, ptrdiff_t c); +static int game_count_nclear (ptrdiff_t r, ptrdiff_t c); +static void game_flag_recursive (ptrdiff_t r, ptrdiff_t c); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void game_init (void) +{ + unsigned seed; + + seed = alx_seed_mix(clock(), time(NULL), getpid()); + srand(seed); +} + +void game_init_rand (ptrdiff_t rows, ptrdiff_t cols, int mines, + ptrdiff_t pos_row, ptrdiff_t pos_col) +{ + + /* size & mines */ + game_board.rows = rows; + game_board.cols = cols; + game_board.mines = mines; + + /* clear */ + game_init_clr(); + + /* place mines */ + game_init_mines(pos_row, pos_col); + + /* calc adjacency numbers */ + game_init_adjnums(); +} + +int game_init_load (ptrdiff_t *rows, ptrdiff_t *cols) +{ + + if (load_game_file()) + return -1; + game_board.state = GAME_STATE_PLAYING; + *rows = game_board.rows; + *cols = game_board.cols; + + return 0; +} + +void game_action (int action, ptrdiff_t row, ptrdiff_t col) +{ + + switch (action) { + case GAME_ACT_STEP: + game_step(row, col); + break; + case GAME_ACT_FLAG: + game_flag(row, col); + break; + case GAME_ACT_FLAG_POSSIBLE: + game_possible(row, col); + break; + case GAME_ACT_RM_FLAG: + game_rmflag(row, col); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* * * * * * * * * * + * * * Init * * * * * * * + * * * * * * * * * */ +static void game_init_clr (void) +{ + + for (ptrdiff_t i = 0; i < game_board.rows; i++) { + for (ptrdiff_t j = 0; j < game_board.cols; j++) { + game_board.gnd[i][j] = GAME_MINE_NO; + game_board.usr[i][j] = GAME_USR_HIDDEN; + } + } + game_board.flags = 0; + game_board.clr = 0; + game_board.state = GAME_STATE_PLAYING; +} + +static void game_init_mines (ptrdiff_t pos_row, ptrdiff_t pos_col) +{ + /* place mines */ + int i; + ptrdiff_t r; + ptrdiff_t c; + + i = 0; + while (i < game_board.mines) { + r = (rand() % game_board.rows); + c = (rand() % game_board.cols); + + if (game_board.gnd[r][c] == GAME_MINE_NO) { + /* first step is safe */ + if (!((r == pos_row) && (c == pos_col))) { + game_board.gnd[r][c] = GAME_MINE_YES; + i++; + } + } + } +} + +static void game_init_adjnums (void) +{ + + for (ptrdiff_t r = 0; r < game_board.rows; r++) { + for (ptrdiff_t c = 0; c < game_board.cols; c++) { + if (game_board.gnd[r][c] >= GAME_MINE_YES) { + for (ptrdiff_t i = r-1; i < r+2; i++) { + for (ptrdiff_t j = c-1; j < c+2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + game_board.gnd[i][j]++; + } + } + } + } + } + } + } +} + +/* * * * * * * * * * + * * * Step * * * * * * * + * * * * * * * * * */ +static void game_step (ptrdiff_t r, ptrdiff_t c) +{ + + switch (game_board.usr[r][c]) { + case GAME_USR_HIDDEN: + case GAME_USR_POSSIBLE: + game_discover(r, c); + break; + case GAME_USR_CLEAR: + game_big_step(r, c); + break; + } +} + +static void game_discover (ptrdiff_t r, ptrdiff_t c) +{ + int safe_fields; + + 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; + + } else if (game_board.usr[r][c] != GAME_USR_CLEAR) { + game_board.usr[r][c] = GAME_USR_CLEAR; + game_board.clr++; + + if (game_board.clr == safe_fields) + game_board.state = GAME_STATE_SAFE; + else if (game_board.gnd[r][c] == GAME_MINE_NO) + game_discover_recursive(r, c); + } +} + +static void game_discover_recursive (ptrdiff_t r, ptrdiff_t c) +{ + + for (ptrdiff_t i = r - 1; i < r + 2; i++) { + for (ptrdiff_t j = c - 1; j < c + 2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + game_discover(i, j); + } + } + } + } +} + +static void game_big_step (ptrdiff_t r, ptrdiff_t c) +{ + int cnt; + + cnt = game_count_flags(r, c); + if (cnt && (game_board.gnd[r][c] == cnt)) + game_step_recursive(r, c); +} + +static int game_count_flags (ptrdiff_t r, ptrdiff_t c) +{ + int cnt; + + cnt = 0; + for (ptrdiff_t i = r - 1; i < r + 2; i++) { + for (ptrdiff_t j = c - 1; j < c + 2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + if (game_board.usr[i][j] == GAME_USR_FLAG) + cnt++; + } + } + } + } + + return cnt; +} + +static void game_step_recursive (ptrdiff_t r, ptrdiff_t c) +{ + + for (ptrdiff_t i = r - 1; i < r + 2; i++) { + for (ptrdiff_t j = c - 1; j < c + 2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + switch (game_board.usr[i][j]) { + case GAME_USR_HIDDEN: + case GAME_USR_POSSIBLE: + game_discover(i, j); + break; + } + } + } + } + } +} + +/* * * * * * * * * * + * * * Flag * * * * * * * + * * * * * * * * * */ +static void game_flag (ptrdiff_t r, ptrdiff_t c) +{ + + switch (game_board.usr[r][c]) { + case GAME_USR_HIDDEN: + game_board.usr[r][c] = GAME_USR_FLAG; + game_board.flags++; + break; + + case GAME_USR_FLAG: + game_board.usr[r][c] = GAME_USR_POSSIBLE; + game_board.flags--; + break; + + case GAME_USR_POSSIBLE: + game_rmflag(r, c); + break; + + case GAME_USR_CLEAR: + game_all_flags(r, c); + break; + } +} + +static void game_possible (ptrdiff_t r, ptrdiff_t c) +{ + + switch (game_board.usr[r][c]) { + case GAME_USR_HIDDEN: + game_board.usr[r][c] = GAME_USR_POSSIBLE; + break; + + case GAME_USR_POSSIBLE: + game_rmflag(r, c); + break; + } +} + +static void game_rmflag (ptrdiff_t r, ptrdiff_t c) +{ + + switch (game_board.usr[r][c]) { + case GAME_USR_FLAG: + game_board.usr[r][c] = GAME_USR_HIDDEN; + game_board.flags--; + break; + + case GAME_USR_POSSIBLE: + game_board.usr[r][c] = GAME_USR_HIDDEN; + break; + } +} + +static void game_all_flags (ptrdiff_t r, ptrdiff_t c) +{ + int cnt; + + cnt = game_count_nclear(r, c); + if (cnt && (game_board.gnd[r][c] == cnt)) + game_flag_recursive(r, c); +} + +static int game_count_nclear (ptrdiff_t r, ptrdiff_t c) +{ + int cnt; + + cnt = 0; + for (ptrdiff_t i = r - 1; i < r + 2; i++) { + for (ptrdiff_t j = c - 1; j < c + 2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + if (game_board.usr[i][j] != GAME_USR_CLEAR) + cnt++; + } + } + } + } + + return cnt; +} + +static void game_flag_recursive (ptrdiff_t r, ptrdiff_t c) +{ + + for (ptrdiff_t i = r - 1; i < r + 2; i++) { + for (ptrdiff_t j = c - 1; j < c + 2; j++) { + if (i >= 0 && i < game_board.rows) { + if (j >= 0 && j < game_board.cols) { + switch (game_board.usr[i][j]) { + case GAME_USR_HIDDEN: + case GAME_USR_POSSIBLE: + game_board.usr[i][j] = GAME_USR_FLAG; + game_board.flags++; + break; + } + } + } + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/game/iface.c b/src/game/iface.c new file mode 100755 index 0000000..13d9b93 --- /dev/null +++ b/src/game/iface.c @@ -0,0 +1,543 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/game/iface.h" + +#include +#include +#include + +#include "mine-sweeper/game/core.h" +#include "mine-sweeper/player/iface.h" +#include "mine-sweeper/save/save.h" +#include "mine-sweeper/save/score.h" +#include "mine-sweeper/xyzzy/xyzzy.h" + + +/****************************************************************************** + ******* 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; +static time_t tim_ini; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Init */ +static void game_iface_init_score (int level); +static void game_iface_init_cheated (void); + /* Actions */ +static void game_iface_act (void); +static void game_iface_playing_act (void); +static void game_iface_xyzzy_act (void); +static void game_iface_cheated_act (void); +static void game_iface_pause_act (void); +static void game_iface_safe_act (void); +static void game_iface_gameover_act (void); + /* Actions: game */ +static void game_iface_act_game (void); + /* Actions: game_iface */ +static void game_iface_pause (void); +static void game_iface_unpause (void); +static void game_iface_xyzzy_on (void); +static void game_iface_xyzzy_off (void); +static void game_iface_save_score (void); +static void game_iface_quit (void); + /* Output */ +static void game_iface_update_out (void); +static void game_iface_update_board (void); +static void game_iface_update_vis (ptrdiff_t r, ptrdiff_t c); +static void game_iface_update_usr (ptrdiff_t r, ptrdiff_t c); + /* Score */ +static void game_iface_update_score (void); + /* Prepare input */ +static void game_iface_clean_in (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void game_iface_init_rand(int level, ptrdiff_t pos_row, ptrdiff_t 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(level); + + game_iface_out.rows = game_board.rows; + game_iface_out.cols = game_board.cols; + game_iface_out.mines = game_board.mines; + game_iface_update_out(); + game_iface_update_score(); + game_iface_clean_in(); +} + +void game_iface_init_load(void) +{ + + game_iface_init_cheated(); + + game_iface_out.rows = game_board.rows; + game_iface_out.cols = game_board.cols; + game_iface_out.mines = game_board.mines; + game_iface_update_out(); + game_iface_clean_in(); +} + +void game_iface (void) +{ + + while (game_iface_out.state != GAME_IFACE_STATE_QUIT) { + game_iface_update_out(); + game_iface_update_score(); + game_iface_clean_in(); + + player_iface(&game_iface_out, &game_iface_score, &game_iface_in); + + game_iface_act(); + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* * * * * * * * * * + * * * Init * * * * * * * + * * * * * * * * * */ +static void game_iface_init_score (int level) +{ + + game_iface_score.level = level; + tim_ini = time(NULL); + game_iface_score.clicks = 1; +} + +static void game_iface_init_cheated (void) +{ + + game_iface_out.state = GAME_IFACE_STATE_CHEATED; + game_iface_score.level = GAME_IFACE_LVL_CUSTOM; + game_iface_score.time = CHEATED; + game_iface_score.clicks = CHEATED; +} + +/* * * * * * * * * * + * * * Actions * * * * * * + * * * * * * * * * */ +static void game_iface_act (void) +{ + + switch (game_iface_out.state) { + case GAME_IFACE_STATE_PLAYING: + game_iface_playing_act(); + break; + case GAME_IFACE_STATE_CHEATED: + game_iface_cheated_act(); + break; + case GAME_IFACE_STATE_XYZZY: + game_iface_xyzzy_act(); + break; + case GAME_IFACE_STATE_PAUSE: + game_iface_pause_act(); + break; + case GAME_IFACE_STATE_SAFE: + game_iface_safe_act(); + break; + case GAME_IFACE_STATE_GAMEOVER: + game_iface_gameover_act(); + break; + } +} + +static void game_iface_playing_act (void) +{ + + switch (game_iface_in.action) { + case GAME_IFACE_ACT_PLAY: + game_iface_act_game(); + break; + case GAME_IFACE_ACT_PAUSE: + game_iface_pause(); + 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; + } +} + +static void game_iface_xyzzy_act (void) +{ + bool wh; + + xyzzy_init(); + + wh = true; + while (wh) { + switch (game_iface_in.action) { + case GAME_IFACE_ACT_PLAY: + 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; + } + } +} + +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; + } +} + +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; + } +} + +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; + } +} + +static void game_iface_gameover_act (void) +{ + + switch (game_iface_in.action) { + case GAME_IFACE_ACT_QUIT: + game_iface_quit(); + break; + } +} + +/* * * * * * * * * * + * * * Actions: game * * * * * + * * * * * * * * * */ +static void game_iface_act_game (void) +{ + + for (ptrdiff_t i = 0; i < game_board.rows; i++) { + for (ptrdiff_t j = 0; j < game_board.cols; j++) { + if (game_iface_in.act_game[i][j]) { + game_action(game_iface_in.act_game[i][j], i, j); + game_iface_score.clicks++; + } + } + } +} + +/* * * * * * * * * * + * * * Actions: game_iface * * * * * + * * * * * * * * * */ +static void game_iface_pause (void) +{ + time_t tim_now; + + tim_now = time(NULL); + game_iface_score.time = (int)(tim_now - tim_ini); + game_iface_out.state = GAME_IFACE_STATE_PAUSE; +} + +static void game_iface_unpause (void) +{ + time_t tim_now; + + tim_now = time(NULL); + tim_ini = tim_now - (time_t)game_iface_score.time; + game_iface_out.state = GAME_IFACE_STATE_PLAYING; +} + +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_LVL_BEGINNER: + save_game_file(BOARDS_BEGINNER_DIR); + save_score(&game_iface_score); + break; + case GAME_IFACE_LVL_INTERMEDIATE: + save_game_file(BOARDS_INTERMEDIATE_DIR); + save_score(&game_iface_score); + break; + case GAME_IFACE_LVL_EXPERT: + save_game_file(BOARDS_EXPERT_DIR); + save_score(&game_iface_score); + break; + case GAME_IFACE_LVL_CUSTOM: + save_game_file(BOARDS_CUSTOM_DIR); + break; + } +} + +static void game_iface_quit (void) +{ + + game_iface_out.state = GAME_IFACE_STATE_QUIT; +} + +/* * * * * * * * * * + * * * Output * * * * * * + * * * * * * * * * */ +static void game_iface_update_out (void) +{ + + game_iface_out.flags = game_board.flags; + game_iface_out.clr = game_board.clr; + + switch (game_board.state) { + 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; + } + + game_iface_update_board(); +} + +static void game_iface_update_board (void) +{ + int i; + int j; + + for (i = 0; i < game_board.rows; i++) { + for (j = 0; j < game_board.cols; j++) { + game_iface_update_vis(i, j); + game_iface_update_usr(i, j); + } + } +} + +static void game_iface_update_vis (ptrdiff_t r, ptrdiff_t c) +{ + int field_vis; + + switch (game_iface_out.state) { + case GAME_IFACE_STATE_CHEATED: + case GAME_IFACE_STATE_XYZZY: + case GAME_IFACE_STATE_PLAYING: + switch (game_board.usr[r][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; + + 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; + else + 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; + else + 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; + else + field_vis = GAME_IFACE_VIS_POSSIBLE_FALSE; + break; + } + break; + default: + field_vis = GAME_IFACE_VIS_HIDDEN_FIELD; + break; + } + + game_iface_out.visible[r][c] = field_vis; +} + +static void game_iface_update_usr (ptrdiff_t r, ptrdiff_t c) +{ + int field_usr; + + switch (game_board.usr[r][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; + } + + game_iface_out.usr[r][c] = field_usr; +} + +/* * * * * * * * * * + * * * Score * * * * * * * + * * * * * * * * * */ +static void game_iface_update_score (void) +{ + time_t tim_now; + + switch (game_iface_out.state) { + case GAME_IFACE_STATE_PLAYING: + 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_LVL_CUSTOM; + game_iface_score.time = CHEATED; + game_iface_score.clicks = CHEATED; + break; + } +} + +/* * * * * * * * * * + * * * Prepare input * * * * * * + * * * * * * * * * */ +static void game_iface_clean_in (void) +{ + + for (ptrdiff_t i = 0; i < game_board.rows; i++) { + for (ptrdiff_t 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; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/main.c b/src/main.c old mode 100644 new mode 100755 index 84349e1..db194a5 --- a/src/main.c +++ b/src/main.c @@ -6,20 +6,18 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include +#include - #include +#include "libalx/extra/ncurses/common.h" - #include "libalx/curses/alx_ncur.h" - - #include "about.h" - #include "game.h" - #include "menu_iface.h" - #include "player_iface.h" - #include "parser.h" - #include "save.h" - #include "score.h" - #include "start.h" +#include "mine-sweeper/about/about.h" +#include "mine-sweeper/ctrl/start.h" +#include "mine-sweeper/game/core.h" +#include "mine-sweeper/menu/iface.h" +#include "mine-sweeper/menu/parser.h" +#include "mine-sweeper/player/iface.h" +#include "mine-sweeper/save/save.h" +#include "mine-sweeper/save/score.h" /****************************************************************************** @@ -36,14 +34,10 @@ int main (int argc, char *argv[]) { init_all(&argc, &argv); - /* Print copyright () and wait for any key to continue */ print_share_file(SHARE_COPYRIGHT); - getchar(); - /* Start () */ start_switch(); - /* Menu () */ menu_iface(); cleanup(); @@ -57,17 +51,14 @@ int main (int argc, char *argv[]) ******************************************************************************/ static void init_all (int *argc, char *(*argv[])) { - /* Init gtk & curses */ - gtk_init_check(argc, argv); - alx_start_curses(); - alx_pause_curses(); + + alx_ncurses_init(); + alx_ncurses_pause(); /* Init modules */ menu_iface_init(); game_init(); - about_init(); save_init(); - score_init(); /* Modes */ start_mode = START_FOO; @@ -77,19 +68,13 @@ static void init_all (int *argc, char *(*argv[])) /* Parse command line options */ parser(*argc, *argv); - - /* Init iface */ - menu_iface_init_iface(); } static void cleanup (void) { - /* Clean iface */ - menu_iface_cleanup(); - /* End curses */ - alx_resume_curses(); - alx_end_curses(); + alx_ncurses_resume(); + alx_ncurses_deinit(); } diff --git a/src/menu/clui.c b/src/menu/clui.c new file mode 100755 index 0000000..d4f9118 --- /dev/null +++ b/src/menu/clui.c @@ -0,0 +1,243 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/menu/clui.h" + +#include +#include +#include + +#include "libalx/base/stdio/get.h" + +#include "mine-sweeper/about/about.h" +#include "mine-sweeper/ctrl/start.h" +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/menu/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define ROWS_CLUI_MAX (99) +#if (ROWS_CLUI_MAX > ROWS_MAX) + #error "rows max (clui)" +#endif + +#define COLS_CLUI_MAX (26) +#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 c; + + c = 'n'; + printf("Read 'Disclaimer of warranty'? (yes/NO): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'y' || c == 'Y') { + printf(" >yes\n"); + print_share_file(SHARE_DISCLAIMER); + } else { + printf(" >NO\n"); + } + + c = 'n'; + printf("Read 'License'? (yes/NO): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'y' || c == 'Y') { + printf(" >yes\n"); + print_share_file(SHARE_LICENSE); + } else { + printf(" >NO\n"); + } +#if 0 + printf("Game interface? (NCURSES/text): "); + scanf(" %c%*s ", &c); + if (c == 't' || c == 'T') { + printf(" >text\n"); + // FIXME + } else { + printf(" >NCURSES\n"); + // FIXME + } +#endif + c = 'n'; + printf("New game or load game? (NEW/load): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'l' || c == 'L') { + printf(" >load\n"); + menu_clui_load(); + } else { + printf(" >NEW\n"); + menu_clui_rand(); + } + + return; + + +err_fgets: + printf("fgets() error\n"); + exit(EXIT_FAILURE); +err_sscanf: + printf("sscanf() error\n"); + exit(EXIT_FAILURE); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_clui_rand (void) +{ + unsigned seed; + char buff [BUFF_SIZE]; + char c; + + /* Random */ + start_mode = START_RAND; + + c = 'n'; + printf("Set seed for random generator? (yes/NO): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'y' || c == 'Y') { + printf(" >yes\n"); + seed = alx_get_uint(0, 1, UINT_MAX, "Seed:", NULL, 2); + srand(seed); + } else { + printf(" >NO\n"); + } + + c = 'b'; + printf("Level? (BEGINNER/intermediate/(expert)/custom): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'i' || c == 'I') { + printf(" >intermediate\n"); + menu_iface_variables.level = GAME_IFACE_LVL_INTERMEDIATE; + menu_clui_start(); + } else if (c == 'e' || c == 'E') { + printf(" >expert\n"); + menu_iface_variables.level = GAME_IFACE_LVL_EXPERT_INV; + menu_clui_start(); + } else if (c == 'c' || c == 'C') { + printf(" >custom\n"); + menu_iface_variables.level = GAME_IFACE_LVL_CUSTOM; + menu_clui_custom(); + } else { + printf(" >BEGINNER\n"); + menu_iface_variables.level = GAME_IFACE_LVL_BEGINNER; + menu_clui_start(); + } + + return; + + +err_fgets: + printf("fgets() error\n"); + exit(EXIT_FAILURE); +err_sscanf: + printf("sscanf() error\n"); + exit(EXIT_FAILURE); +} + +static void menu_clui_custom (void) +{ + + start_mode = START_RAND; + + menu_iface_variables.rows = alx_get_pdif(2, menu_iface_variables.rows, + ROWS_CLUI_MAX, "Rows:", NULL, 2); + menu_iface_variables.cols = alx_get_pdif(2, menu_iface_variables.cols, + COLS_CLUI_MAX, "Columns:", NULL, 2); + menu_iface_variables.p = alx_get_dbl(0.0, menu_iface_variables.p, 1.0, + "Proportion:", NULL, 2); + + menu_clui_start(); +} + +static void menu_clui_load (void) +{ + + 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) +{ + char buff [BUFF_SIZE]; + char c; + + printf(" >>START:\n"); + start_switch(); + + c = 'm'; + printf("Play again? (MENU/play/exit): "); + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %c", &c) != 1) + goto err_sscanf; + if (c == 'p' || c == 'P') { + printf(" >play\n"); + menu_clui_start(); + } else if (c == 'e' || c == 'E') { + printf(" >exit!\n"); + } else { + printf(" >MENU\n"); + menu_clui(); + } + + return; + + +err_fgets: + printf("fgets() error\n"); + exit(EXIT_FAILURE); +err_sscanf: + printf("sscanf() error\n"); + exit(EXIT_FAILURE); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/iface.c b/src/menu/iface.c new file mode 100755 index 0000000..3f241bb --- /dev/null +++ b/src/menu/iface.c @@ -0,0 +1,101 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/menu/iface.h" + +#include +#include + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/ctrl/start.h" +#include "mine-sweeper/menu/clui.h" +#include "mine-sweeper/menu/tui.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +bool flag_exit; +int menu_iface_mode; +struct Menu_Iface_Variables menu_iface_variables; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_iface_init (void) +{ + + menu_iface_variables.level = GAME_IFACE_LVL_BEGINNER; + menu_iface_variables.rows = 8; + menu_iface_variables.cols = 8; + menu_iface_variables.p = 0.16; +} + +void menu_iface_board (int *level, ptrdiff_t *rows, ptrdiff_t *cols, int *mines) +{ + + *level = menu_iface_variables.level; + + /* size & number of mines */ + switch (*level) { + case GAME_IFACE_LVL_BEGINNER: + *rows = GAME_IFACE_LVL_BEGINNER_ROWS; + *cols = GAME_IFACE_LVL_BEGINNER_COLS; + *mines = GAME_IFACE_LVL_BEGINNER_MINES; + break; + case GAME_IFACE_LVL_INTERMEDIATE: + *rows = GAME_IFACE_LVL_INTERMEDIATE_ROWS; + *cols = GAME_IFACE_LVL_INTERMEDIATE_COLS; + *mines = GAME_IFACE_LVL_INTERMEDIATE_MINES; + break; + case GAME_IFACE_LVL_EXPERT: + *rows = GAME_IFACE_LVL_EXPERT_ROWS; + *cols = GAME_IFACE_LVL_EXPERT_COLS; + *mines = GAME_IFACE_LVL_EXPERT_MINES; + break; + case GAME_IFACE_LVL_EXPERT_INV: + *rows = GAME_IFACE_LVL_EXPERT_COLS; + *cols = GAME_IFACE_LVL_EXPERT_ROWS; + *mines = GAME_IFACE_LVL_EXPERT_MINES; + break; + case GAME_IFACE_LVL_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; + } +} + +void menu_iface (void) +{ + + start_mode = START_RAND; + + if (flag_exit) + return; + + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + case MENU_IFACE_CLUI: + menu_clui(); + break; + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/parser.c b/src/menu/parser.c new file mode 100755 index 0000000..95815d5 --- /dev/null +++ b/src/menu/parser.c @@ -0,0 +1,225 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/menu/parser.h" + +#include +#include +#include + +#include "libalx/base/stdlib/seed_mix.h" + +#include "mine-sweeper/about/about.h" +#include "mine-sweeper/ctrl/start.h" +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/menu/iface.h" +#include "mine-sweeper/player/iface.h" +#include "mine-sweeper/save/save.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define OPT_LIST "xhLuv""a:b:f:i:p:r:s:" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_rows (char *argument); +static void parse_columns (char *argument); +static void parse_file (char *argument); +static void parse_iface (char *argument); +static void parse_proportion (char *argument); +#if 0 +static void parse_rand_seed (char *argument); +#endif +static void parse_start (char *argument); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void parser (int argc, char *argv[]) +{ + int opt = 0; + int opt_index = 0; + + const struct option long_options[] = { + /* Standard */ + {"exit", no_argument, 0, 'x'}, + {"help", no_argument, 0, 'h'}, + {"license", no_argument, 0, 'L'}, + {"usage", no_argument, 0, 'u'}, + {"version", no_argument, 0, 'v'}, + /* Non-standard */ + {"rows", required_argument, 0, 'a'}, + {"columns", required_argument, 0, 'b'}, + {"file", required_argument, 0, 'f'}, + {"iface", required_argument, 0, 'i'}, + {"proportion", required_argument, 0, 'p'}, +// {"rand-seed", required_argument, 0, 'r'}, + {"start", required_argument, 0, 's'}, + /* Null */ + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, + &opt_index)) != -1) { + + switch (opt) { + /* Standard */ + 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); + + /* Non-standard */ + 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; +# if 0 +// for DEVEL + case 'r': + parse_rand_seed(optarg); + break; +# endif + case 's': + parse_start(optarg); + break; + case '?': + /* getopt_long already printed an error message. */ + default: + print_share_file(SHARE_USAGE); + exit(EXIT_FAILURE); + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +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"); + printf("It must be an integer [%i U %i]\n", 2, ROWS_MAX); + exit(EXIT_FAILURE); + } +} + +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"); + printf("It must be an integer [%i U %i]\n", 2, COLS_MAX); + exit(EXIT_FAILURE); + } +} + +static void parse_file (char *argument) +{ + FILE *fp; + + // FIXME + fp = fopen(argument, "r"); + if (!fp) + goto err_fp; + fclose(fp); + + saved_path[0] = '\0'; + snprintf(saved_name, FILENAME_MAX, argument); + + return; + +err_fp: + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); +} + +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)) { + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", + MENU_IFACE_CLUI, MENU_IFACE_GUI); + exit(EXIT_FAILURE); + } +} + +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"); + printf("It must be a real [0 U 1]\n"); + exit(EXIT_FAILURE); + } +} +#if 0 +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"); + printf("It must be an integer [%i U %i]\n", + START_FOO, START_LOAD); + exit(EXIT_FAILURE); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/tui.c b/src/menu/tui.c new file mode 100755 index 0000000..90fec38 --- /dev/null +++ b/src/menu/tui.c @@ -0,0 +1,413 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/menu/tui.h" + +#include +#include +#include + +#include + +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/wait.h" +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" +#include "libalx/extra/ncurses/menu.h" + +#include "mine-sweeper/about/about.h" +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/save/save.h" +#include "mine-sweeper/save/score.h" +#include "mine-sweeper/ctrl/start.h" +#include "mine-sweeper/menu/iface.h" + + +/****************************************************************************** + ******* 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 + +#define BUFF_SIZE_TEXT (1048576) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void); +static void menu_tui_select (void); +static void menu_tui_level (void); +static void menu_tui_custom (void); +#if 0 +static void menu_tui_devel (void); +#endif +#if 0 +static void menu_tui_verbose (void); +#endif + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + int h; + int w; + bool wh; + int sw; + + alx_ncurses_resume(); + + /* Menu dimensions & options */ + h = 10; + w = 34; + static const struct Alx_Ncurses_Menu mnu[] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + /* Menu */ + wh = true; + while (wh) { + /* Menu loop */ + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "MENU:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + case 1: + menu_tui_continue(); + break; + case 2: + alx_ncurses_pause(); + print_share_file(SHARE_DISCLAIMER); + alx_ncurses_resume(); + break; + case 3: + alx_ncurses_pause(); + print_share_file(SHARE_LICENSE); + alx_ncurses_resume(); + break; + } + } + + alx_ncurses_pause(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + int w2; + int r2; + bool wh; + int sw; + + /* Menu dimensions & options */ + h = 18; + w = 50; + r = 1; + c = (80 - w) / 2; + static const struct Alx_Ncurses_Menu mnu[] = { + {11, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {4, 4, "[2] Select map"}, + {5, 4, "[3] Change difficulty"}, + {6, 4, "[4] Change file name"}, + {7, 4, "[5] Hi scores"}/*, + {9, 4, "[6] DEVEL"}*/ + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = {"File name:"}; + + /* Menu */ + wh = true; + while (wh) { + /* Menu loop */ + win = newwin(h, w, r, c); + mvwprintw(win, mnu[4].r, mnu[4].c, "%s (File: \"%s\")", mnu[4].t, saved_name); + wrefresh(win); + sw = alx_ncurses_menu_w(win, ARRAY_SIZE(mnu), mnu, "CONTINUE:"); + + /* Selection */ + switch (sw) { + case 0: + alx_ncurses_delwin(win); + wh = false; + break; + case 1: + alx_ncurses_delwin(win); + alx_ncurses_pause(); + start_switch(); + alx_ncurses_resume(); + break; + case 2: + alx_ncurses_delwin(win); + menu_tui_select(); + break; + case 3: + alx_ncurses_delwin(win); + menu_tui_level(); + break; + case 4: + save_clr(); + alx_ncurses_get_fname(saved_path, saved_name, true, w2, r2, + txt[0], NULL, 2); + alx_ncurses_delwin(win); + break; + case 5: + alx_ncurses_delwin(win); + alx_ncurses_pause(); + print_scores(); + alx_ncurses_resume(); + break; +/* + case 6: + alx_ncurses_delwin(win); + menu_tui_devel(); + break; +*/ + } + } +} + +static void menu_tui_select (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + int sw; + + /* Menu dimensions & options */ + h = 9; + w = 70; + r = 1; + c = (80 - w) / 2; + static const struct Alx_Ncurses_Menu mnu[] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] New map"}, + {4, 4, "[2] Load map"} + }; + + /* Menu loop */ + win = newwin(h, w, r, c); + mvwprintw(win, mnu[2].r, mnu[2].c, "%s (File: \"%s\")", mnu[1].t, saved_name); + wrefresh(win); + sw = alx_ncurses_menu_w(win, ARRAY_SIZE(mnu), mnu, "SELECT MAP:"); + alx_ncurses_delwin(win); + + /* Selection */ + switch (sw) { + case 1: + start_mode = START_RAND; + break; + case 2: + start_mode = START_LOAD; + break; + } + +} + +static void menu_tui_level (void) +{ + int h; + int w; + int sw; + + /* Menu dimensions & options */ + h = 10; + w = 70; + static const struct Alx_Ncurses_Menu mnu[] = { + {7, 4, "[0] Back"}, + {2, 4, "[1] Beginner"}, + {3, 4, "[2] Intermediate"}, + {4, 4, "[3] Expert"}, + {5, 4, "[4] Custom"} + }; + + /* Menu loop */ + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "SELECT LEVEL:"); + + /* Selection */ + switch (sw) { + case 1: + menu_iface_variables.level = GAME_IFACE_LVL_BEGINNER; + break; + + case 2: + menu_iface_variables.level = GAME_IFACE_LVL_INTERMEDIATE; + break; + + case 3: + menu_iface_variables.level = GAME_IFACE_LVL_EXPERT; + break; + + case 4: + menu_iface_variables.level = GAME_IFACE_LVL_CUSTOM; + menu_tui_custom(); + break; + } + +} + +static void menu_tui_custom (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + int w2; + int r2; + bool wh; + int sw; + + /* Menu dimensions & options */ + h = 16; + w = 76; + r = 1; + c = (80 - w) / 2; + static const struct Alx_Ncurses_Menu mnu[] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Change rows:"}, + {4, 4, "[2] Change columns:"}, + {6, 4, "[3] Change proportion of mines:"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = { + "Rows:", + "Columns:", + "Proportion:" + }; + + /* Menu */ + win = newwin(h, w, r, c); + + /* Menu loop */ + wh = true; + while (wh) { + mvwprintw(win, mnu[1].r, mnu[1].c, "%s rows\t\t(%i)", + mnu[1].t, menu_iface_variables.rows); + mvwprintw(win, mnu[2].r, mnu[2].c, "%s cols\t\t(%i)", + mnu[2].t, menu_iface_variables.cols); + mvwprintw(win, mnu[3].r, mnu[3].c, "%s p\t(%lf)", + mnu[3].t, menu_iface_variables.p); + wrefresh(win); + + /* Selection */ + sw = alx_ncurses_menu_w(win, ARRAY_SIZE(mnu), mnu, "Custom:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + menu_iface_variables.rows = alx_ncurses_get_pdif( + 2, menu_iface_variables.rows, ROWS_TUI_MAX, + w2, r2, txt[sw - 1], NULL, 2); + break; + case 2: + menu_iface_variables.cols = alx_ncurses_get_pdif( + 2, menu_iface_variables.cols, COLS_TUI_MAX, + w2, r2, txt[sw - 1], NULL, 2); + break; + case 3: + menu_iface_variables.p = alx_ncurses_get_dbl( + 0.0, menu_iface_variables.p, 1.0, + w2, r2, txt[sw - 1], NULL, 2); + break; + } + + } + + alx_ncurses_delwin(win); +} +#if 0 +static void menu_tui_devel (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + int w2; + int r2; + bool wh; + int sw; + int seed; + + h = 12; + w = 50; + r = 1; + c = (80 - w) / 2; + static const struct Alx_Ncurses_Menu mnu[] = { + {5, 4, "[0] Back"}, + {2, 4, "[1] Change seed (srand)"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = {"Seed:"}; + + /* Menu */ + win = newwin(h, w, r, c); + + /* Menu loop */ + wh = true; + while (wh) { + /* Selection */ + sw = alx_ncurses_menu_2(win, ARRAY_SIZE(mnu), mnu, "DEVELOPER OPTIONS:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + seed = alx_w_getint(w2, r2, txt[0], + -INFINITY, 1, INFINITY, NULL); + srand(seed); + break; + } + } + + alx_win_del(win); +} +#endif + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/player/clui.c b/src/player/clui.c new file mode 100755 index 0000000..ae936db --- /dev/null +++ b/src/player/clui.c @@ -0,0 +1,501 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/player/clui.h" + +#include +#include + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +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 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 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_start (void); +static void show_help_play (void); +static void show_help_pause (void); +static void show_help_xyzzy (void); +static void show_help_cheat (void); +static void show_help_safe (void); +static void show_help_gameover (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void player_clui_start (const struct Player_Iface_Position *position, + const char *title, const char *subtitle, + int *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) +{ + + if (oldaction != PLAYER_IFACE_ACT_FOO) { + show_help(board); + show_board(board, position, title, subtitle); + } + *action = usr_input(); + oldaction = *action; +} + +void player_clui_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]) +{ + + (void)fpath; + + printf("File name:\n"); + fgets(fname, FILENAME_MAX, stdin); +} + +void player_clui_score_name (char player_name[static restrict BUFSIZ]) +{ + + printf("Your name:\n"); + fgets(player_name, BUFSIZ, stdin); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* * * * * * * * * * + * * * Start * * * * * * * + * * * * * * * * * */ +static void show_board_start(const struct Player_Iface_Position *position, + const char *title, const char *subtitle) +{ + + printf("________________________________________________________________________________\n"); + board_loop_start(position); + printf("%s - %s\n", subtitle, title); + printf("--------------------------------------------------------------------------------\n"); +} + +static void board_loop_start(const struct Player_Iface_Position *position) +{ + int i; + int j; + char c; + + putchar('\n'); + for (i = 0; i < position->rows; i++) { + for (j = 0; j < position->cols; j++) { + c = PLAYER_CLUI_CHAR_HIDDEN_FIELD; + + /* Print char */ + if (i == position->row && j == position->col) { + putchar('<'); + putchar(c); + putchar('>'); + } else { + putchar(' '); + putchar(c); + putchar(' '); + } + } + putchar('\n'); + } + putchar('\n'); +} + +/* * * * * * * * * * + * * * Play * * * * * * + * * * * * * * * * */ +static void show_board (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position, + const char *title, const char *subtitle) +{ + + printf("________________________________________________________________________________\n"); + board_loop(board, position); + printf("%s - %s\n", subtitle, title); + printf("--------------------------------------------------------------------------------\n"); + +} + +static void board_loop (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position) +{ + int i; + int j; + char c; + + putchar('\n'); + for (i = 0; i < board->rows; i++) { + for (j = 0; j < board->cols; j++) { + c = set_char(board->visible[i][j]); + + /* Print char */ + if (i == position->row && j == position->col) { + putchar('<'); + putchar(c); + putchar('>'); + } else { + putchar(' '); + putchar(c); + putchar(' '); + } + } + putchar('\n'); + } + putchar('\n'); +} + +static char set_char (int game_iface_visible) +{ + char c; + + switch (game_iface_visible) { + case GAME_IFACE_VIS_KBOOM: + c = PLAYER_CLUI_CHAR_KBOOM; + break; + case GAME_IFACE_VIS_HIDDEN_FIELD: + c = PLAYER_CLUI_CHAR_HIDDEN_FIELD; + break; + case GAME_IFACE_VIS_HIDDEN_MINE: + c = PLAYER_CLUI_CHAR_HIDDEN_MINE; + break; + case GAME_IFACE_VIS_HIDDEN_SAFE: + c = PLAYER_CLUI_CHAR_HIDDEN_SAFE; + break; + case GAME_IFACE_VIS_SAFE_MINE: + c = PLAYER_CLUI_CHAR_SAFE_MINE; + break; + case GAME_IFACE_VIS_0: + c = PLAYER_CLUI_CHAR_0; + break; + case GAME_IFACE_VIS_1: + c = PLAYER_CLUI_CHAR_1; + break; + case GAME_IFACE_VIS_2: + c = PLAYER_CLUI_CHAR_2; + break; + case GAME_IFACE_VIS_3: + c = PLAYER_CLUI_CHAR_3; + break; + case GAME_IFACE_VIS_4: + c = PLAYER_CLUI_CHAR_4; + break; + case GAME_IFACE_VIS_5: + c = PLAYER_CLUI_CHAR_5; + break; + case GAME_IFACE_VIS_6: + c = PLAYER_CLUI_CHAR_6; + break; + case GAME_IFACE_VIS_7: + c = PLAYER_CLUI_CHAR_7; + break; + case GAME_IFACE_VIS_8: + c = PLAYER_CLUI_CHAR_8; + break; + case GAME_IFACE_VIS_FLAG: + c = PLAYER_CLUI_CHAR_FLAG; + break; + case GAME_IFACE_VIS_FLAG_FALSE: + c = PLAYER_CLUI_CHAR_FLAG_FALSE; + break; + case GAME_IFACE_VIS_POSSIBLE: + c = PLAYER_CLUI_CHAR_POSSIBLE; + break; + case GAME_IFACE_VIS_POSSIBLE_FALSE: + c = PLAYER_CLUI_CHAR_POSSIBLE_FALSE; + break; + default: + c = PLAYER_CLUI_CHAR_ERROR; + break; + } + + return c; +} + +/* * * * * * * * * * + * * * Input * * * * * * * + * * * * * * * * * */ +static int usr_input (void) +{ + char buff [BUFF_SIZE]; + char c; + int action; + char *p; + + action = PLAYER_IFACE_ACT_FOO; + + /* Wait for input */ + buff[0] = '\0'; + c = '\0'; + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + p = buff; + + /* Interpret input */ + if (sscanf(p, "%c", &c) != 1) + goto err_sscanf; + p++; + switch (c) { + /* Escape sequence */ + case 27: + /* Arrows */ + if (sscanf(p, "%c", &c) != 1) + goto err_sscanf; + p++; + switch (c) { + case 91: + if (sscanf(p, "%c", &c) != 1) + goto err_sscanf; + p++; + switch (c) { + case 65: + action = PLAYER_IFACE_ACT_MOVE_UP; + break; + + case 66: + action = PLAYER_IFACE_ACT_MOVE_DOWN; + break; + + case 67: + action = PLAYER_IFACE_ACT_MOVE_RIGHT; + break; + + case 68: + action = PLAYER_IFACE_ACT_MOVE_LEFT; + break; + } + break; + } + break; + + case 'h': + action = PLAYER_IFACE_ACT_MOVE_LEFT; + break; + + case 'j': + action = PLAYER_IFACE_ACT_MOVE_DOWN; + break; + + case 'k': + action = PLAYER_IFACE_ACT_MOVE_UP; + break; + + case 'l': + action = PLAYER_IFACE_ACT_MOVE_RIGHT; + break; + + case '+': + action = PLAYER_IFACE_ACT_STEP; + break; + + case ' ': + action = PLAYER_IFACE_ACT_FLAG; + break; + + case 'f': + action = PLAYER_IFACE_ACT_FLAG_POSSIBLE; + break; + + /* ASCII 0x08 is BS */ + case 0x7F: + case 0x08: + action = PLAYER_IFACE_ACT_RM_FLAG; + break; + + case 'p': + action = PLAYER_IFACE_ACT_PAUSE; + break; + + case 's': + action = PLAYER_IFACE_ACT_SAVE; + break; + + case 'x': + /* Special sequence "xyzzy" */ + 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; + + 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; + } + + +err_sscanf: +err_fgets: + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (const struct Game_Iface_Out *board) +{ + + 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; + } +} + +static void show_help_start (void) +{ + + printf("Move |Step |Quit |Confirm\n"); + printf(" hjkl | + | q | Enter\n"); +} + +static void show_help_play (void) +{ + + printf("Move |Step |Flag |? |Remove |Pause |Save |Quit |Confirm\n"); + printf(" hjkl | + | Space| f| BS | p | s | q | Enter\n"); +} + +static void show_help_pause (void) +{ + + printf("Continue |Save |Quit |Confirm\n"); + printf(" p | s | q | Enter"); +} + +static void show_help_xyzzy (void) +{ + + printf("XYZZY |Move |Step |Flag |? |Remove |Save |Quit |Confirm\n"); + printf(" 0 1 2| hjkl | + | Space| f| BS | s | q | Enter\n"); +} + +static void show_help_cheat (void) +{ + + printf("Move |Step |Flag |? |Remove |Save |Quit |Confirm\n"); + printf(" hjkl | + | Space| f| BS | s | q | Enter\n"); +} + +static void show_help_safe (void) +{ + + printf("Save |Quit |Confirm\n"); + printf(" s | q | Enter\n"); +} + +static void show_help_gameover (void) +{ + + printf("Quit |Confirm\n"); + printf(" q | Enter\n"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/player/iface.c b/src/player/iface.c new file mode 100755 index 0000000..5e4bf2f --- /dev/null +++ b/src/player/iface.c @@ -0,0 +1,397 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/player/iface.h" + +#include +#include + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/clui.h" +#include "mine-sweeper/player/tui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define TITLE_SIZE (20) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int player_iface_mode; +/* Static --------------------------------------------------------------------*/ +static struct Player_Iface_Position player_iface_position; +static int player_action; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Actions */ +static void player_iface_act (struct Game_Iface_In *in); + + /* Actions: game iface */ +static void player_iface_act_start (void); +static void player_iface_act_play (struct Game_Iface_In *in); +static void player_iface_act_game (struct Game_Iface_In *in); + + /* Actions: player iface */ +static void player_iface_move_up (void); +static void player_iface_move_down (void); +static void player_iface_move_right (void); +static void player_iface_move_left (void); +static void highlight_cursor (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void player_iface_init (ptrdiff_t rows, ptrdiff_t cols) +{ + + player_iface_position.rows = rows; + player_iface_position.cols = cols; + + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + break; + case PLAYER_IFACE_TUI: + player_tui_init(rows, cols); + break; + } +} + +int player_iface_start (ptrdiff_t *row, ptrdiff_t *col) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int fail; + + snprintf(title, TITLE_SIZE, "Start:"); + snprintf(subtitle, TITLE_SIZE, "00:00 | 0"); + + /* Start position */ + player_iface_position.row = 0; + player_iface_position.col = 0; + player_iface_position.highlight = false; + + /* Loop until first step */ + do { + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + player_clui_start(&player_iface_position, + title, subtitle, &player_action); + break; + case PLAYER_IFACE_TUI: + player_tui_start(&player_iface_position, + title, subtitle, &player_action); + break; + } + + player_iface_act_start(); + } while ((player_action != PLAYER_IFACE_ACT_STEP) && + (player_action != PLAYER_IFACE_ACT_QUIT)); + + *row = player_iface_position.row; + *col = player_iface_position.col; + + switch (player_action) { + case PLAYER_IFACE_ACT_STEP: + fail = 0; + break; + + case PLAYER_IFACE_ACT_QUIT: + fail = -1; + break; + + default: + fail = -2; + break; + } + return fail; +} + +void player_iface (const struct Game_Iface_Out *out, + const struct Game_Iface_Score *score, + struct Game_Iface_In *in) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int hours; + int mins; + int secs; + + /* Title */ + switch (out->state) { + case GAME_IFACE_STATE_XYZZY: + case GAME_IFACE_STATE_CHEATED: + case GAME_IFACE_STATE_PLAYING: + case GAME_IFACE_STATE_PAUSE: + snprintf(title, TITLE_SIZE, "Mines: %i/%i", + out->flags, out->mines); + break; + + case GAME_IFACE_STATE_GAMEOVER: + snprintf(title, TITLE_SIZE, "GAME OVER"); + break; + + case GAME_IFACE_STATE_SAFE: + snprintf(title, TITLE_SIZE, "You win!"); + break; + } + /* Subtitle */ + if (score->time != CHEATED) { + hours = ((int)score->time / 3600); + mins = (((int)score->time % 3600) / 60); + secs = ((int)score->time % 60); + + if (score->time >= 3600) { + snprintf(subtitle, TITLE_SIZE, "%02i:%02i:%02i | %i", + hours, mins, secs, score->clicks); + } else { + snprintf(subtitle, TITLE_SIZE, "%02i:%02i | %i", + mins, secs, score->clicks); + } + } else { + snprintf(subtitle, TITLE_SIZE, "N/A"); + } + + /* Request player action */ + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + player_clui(out, &player_iface_position, title, subtitle, + &player_action); + break; + case PLAYER_IFACE_TUI: + player_tui(out, &player_iface_position, title, subtitle, + &player_action); + break; + } + + player_iface_act(in); +} + +void player_iface_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]) +{ + + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + player_clui_save_name(fpath, fname); + break; + case PLAYER_IFACE_TUI: + player_tui_save_name(fpath, fname); + break; + } +} + +void player_iface_score_name (char player_name[static restrict BUFSIZ]) +{ + + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + player_clui_score_name(player_name); + break; + case PLAYER_IFACE_TUI: + player_tui_score_name(player_name); + break; + } +} + +void player_iface_cleanup (void) +{ + + switch (player_iface_mode) { + case PLAYER_IFACE_CLUI: + break; + case PLAYER_IFACE_TUI: + player_tui_cleanup(); + break; + } + fflush(stdout); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* * * * * * * * * * + * * * Actions * * * * * * + * * * * * * * * * */ +static void player_iface_act (struct Game_Iface_In *in) +{ + + switch (player_action) { + case PLAYER_IFACE_ACT_STEP: + case PLAYER_IFACE_ACT_FLAG: + case PLAYER_IFACE_ACT_FLAG_POSSIBLE: + case PLAYER_IFACE_ACT_RM_FLAG: + player_iface_act_play(in); + break; + case PLAYER_IFACE_ACT_PAUSE: + case PLAYER_IFACE_ACT_SAVE: + case PLAYER_IFACE_ACT_XYZZY_ON: + case PLAYER_IFACE_ACT_XYZZY_OFF: + case PLAYER_IFACE_ACT_XYZZY_LIN: + case PLAYER_IFACE_ACT_XYZZY_P: + case PLAYER_IFACE_ACT_XYZZY_NP: + case PLAYER_IFACE_ACT_QUIT: + player_iface_act_game(in); + break; + case PLAYER_IFACE_ACT_MOVE_UP: + player_iface_move_up(); + break; + case PLAYER_IFACE_ACT_MOVE_DOWN: + player_iface_move_down(); + break; + case PLAYER_IFACE_ACT_MOVE_RIGHT: + player_iface_move_right(); + break; + case PLAYER_IFACE_ACT_MOVE_LEFT: + player_iface_move_left(); + break; + case PLAYER_IFACE_ACT_HIGHLIGHT: + highlight_cursor(); + break; + } +} + +static void player_iface_act_start (void) +{ + + switch (player_action) { + case PLAYER_IFACE_ACT_STEP: + case PLAYER_IFACE_ACT_QUIT: + break; + case PLAYER_IFACE_ACT_MOVE_UP: + player_iface_move_up(); + break; + case PLAYER_IFACE_ACT_MOVE_DOWN: + player_iface_move_down(); + break; + case PLAYER_IFACE_ACT_MOVE_RIGHT: + player_iface_move_right(); + break; + case PLAYER_IFACE_ACT_MOVE_LEFT: + player_iface_move_left(); + break; + case PLAYER_IFACE_ACT_HIGHLIGHT: + highlight_cursor(); + break; + } +} + +/* * * * * * * * * * + * * * Actions: game iface * * * * * + * * * * * * * * * */ +static void player_iface_act_play (struct Game_Iface_In *in) +{ + const int r = player_iface_position.row; + const int c = player_iface_position.col; + + switch (player_action) { + case PLAYER_IFACE_ACT_STEP: + in->act_game[r][c] = GAME_IFACE_GAME_ACT_STEP; + break; + case PLAYER_IFACE_ACT_FLAG: + in->act_game[r][c] = GAME_IFACE_GAME_ACT_FLAG; + break; + case PLAYER_IFACE_ACT_FLAG_POSSIBLE: + in->act_game[r][c] = GAME_IFACE_GAME_ACT_FLAG_POSSIBLE; + break; + case PLAYER_IFACE_ACT_RM_FLAG: + in->act_game[r][c] = GAME_IFACE_GAME_ACT_RM_FLAG; + break; + } + + in->action = GAME_IFACE_ACT_PLAY; +} + +static void player_iface_act_game (struct Game_Iface_In *in) +{ + + switch (player_action) { + case PLAYER_IFACE_ACT_PAUSE: + in->action = GAME_IFACE_ACT_PAUSE; + break; + case PLAYER_IFACE_ACT_SAVE: + in->action = GAME_IFACE_ACT_SAVE; + break; + case PLAYER_IFACE_ACT_XYZZY_ON: + in->action = GAME_IFACE_ACT_XYZZY_ON; + break; + case PLAYER_IFACE_ACT_XYZZY_OFF: + in->action = GAME_IFACE_ACT_XYZZY_OFF; + break; + case PLAYER_IFACE_ACT_XYZZY_LIN: + in->action = GAME_IFACE_ACT_XYZZY_LIN; + break; + case PLAYER_IFACE_ACT_XYZZY_P: + in->action = GAME_IFACE_ACT_XYZZY_P; + break; + case PLAYER_IFACE_ACT_XYZZY_NP: + in->action = GAME_IFACE_ACT_XYZZY_NP; + break; + case PLAYER_IFACE_ACT_QUIT: + in->action = GAME_IFACE_ACT_QUIT; + break; + } +} + +/* * * * * * * * * * + * * * Actions: player iface * * * * + * * * * * * * * * */ +static void player_iface_move_up (void) +{ + + if (player_iface_position.row) + (player_iface_position.row)--; + else + player_iface_position.row = player_iface_position.rows - 1; +} + +static void player_iface_move_down (void) +{ + + if (player_iface_position.row != player_iface_position.rows - 1) + (player_iface_position.row)++; + else + player_iface_position.row = 0; +} + +static void player_iface_move_right (void) +{ + + if (player_iface_position.col != player_iface_position.cols - 1) + (player_iface_position.col)++; + else + player_iface_position.col = 0; +} + +static void player_iface_move_left (void) +{ + + if (player_iface_position.col) + (player_iface_position.col)--; + else + player_iface_position.col = player_iface_position.cols - 1; +} + +static void highlight_cursor (void) +{ + + player_iface_position.highlight = !player_iface_position.highlight; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/player/tui.c b/src/player/tui.c new file mode 100755 index 0000000..d62d06a --- /dev/null +++ b/src/player/tui.c @@ -0,0 +1,854 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/player/tui.h" + +#include +#include +#include + +#include + +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" + +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define REFRESH_TIME_MS (100) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + bool flag_color; +/* Static --------------------------------------------------------------------*/ +static WINDOW *win_board; +static WINDOW *win_help; +static int last_help; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Start */ +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); + + /* 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 board_loop (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position); + +static void highlight_cursor(int c, + const struct Player_Iface_Position *position); + +static int set_char (int tile); +static void show_char (int row, int col, int c); + /* Input */ +static int usr_input (void); + /* Help */ +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); +static void show_help_xyzzy (void); +static void show_help_cheat (void); +static void show_help_safe (void); +static void show_help_gameover (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void player_tui_init (ptrdiff_t rows, ptrdiff_t cols) +{ + int h1; + int w1; + int r1; + int c1; + int h2; + int w2; + int r2; + int c2; + + alx_ncurses_resume(); + + flag_color = false; + if (has_colors()) { + flag_color = true; + /* Clear */ + init_pair(PAIR_1, COLOR_BLUE, COLOR_WHITE); + init_pair(PAIR_2, COLOR_GREEN, COLOR_WHITE); + init_pair(PAIR_3, COLOR_RED, COLOR_WHITE); + init_pair(PAIR_4, COLOR_BLUE, COLOR_WHITE); + init_pair(PAIR_5, COLOR_RED, COLOR_WHITE); + init_pair(PAIR_6, COLOR_CYAN, COLOR_WHITE); + init_pair(PAIR_7, COLOR_BLACK, COLOR_WHITE); + init_pair(PAIR_8, COLOR_BLACK, COLOR_WHITE); + init_pair(PAIR_BLANK, COLOR_BLACK, COLOR_WHITE); + /* Hidden */ + init_pair(PAIR_MINE, COLOR_WHITE, COLOR_BLACK); + init_pair(PAIR_HIDDEN, COLOR_WHITE, COLOR_BLACK); + /* Possible */ + init_pair(PAIR_fail, COLOR_RED, COLOR_BLACK); + init_pair(PAIR_POSSIBLE, COLOR_BLUE, COLOR_BLACK); + /* Flag */ + init_pair(PAIR_FAIL, COLOR_RED, COLOR_BLACK); + init_pair(PAIR_FLAG, COLOR_RED, COLOR_BLACK); + /* Kboom */ + init_pair(PAIR_KBOOM, COLOR_BLACK, COLOR_RED); + /* Highlight */ + init_pair(PAIR_HILITE, COLOR_YELLOW, COLOR_RED); + /* Terminal */ + init_pair(PAIR_TERM, -1, -1); + } + + /* Dimensions: board */ + h1 = rows + 2; + w1 = 2 * cols + 3; + r1 = 0; + c1 = 11; + win_board = newwin(h1, w1, r1, c1); + + /* Dimensions: help */ + 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 */ + keypad(win_board, true); + noecho(); + wtimeout(win_board, REFRESH_TIME_MS); +} + +int player_tui_start (const struct Player_Iface_Position *position, + const char *title, const char *subtitle, + int *action) +{ + + show_help_start(); + show_board_start(position, title, subtitle); + *action = usr_input(); + + return 0; +} + +int player_tui (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position, + const char *title, const char *subtitle, + int *action) +{ + + show_help(board); + show_board(board, position, title, subtitle); + *action = usr_input(); + + return 0; +} + +void player_tui_save_name (const char *fpath, + char fname[static restrict FILENAME_MAX]) +{ + int w; + int r; + + w = 60; + r = 10; + alx_ncurses_get_fname(fpath, fname, false, w, r, "File name:", NULL, 2); +} + +void player_tui_score_name (char player_name[static restrict BUFSIZ]) +{ + int w; + int r; + + w = 60; + r = 10; + alx_ncurses_get_nstr(BUFSIZ, player_name, w, r, "Your name:", NULL); +} + +void player_tui_cleanup (void) +{ + + alx_ncurses_delwin(win_board); + alx_ncurses_delwin(win_help); + alx_ncurses_pause(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* * * * * * * * * * + * * * Start * * * * * * * + * * * * * * * * * */ +static void show_board_start(const struct Player_Iface_Position *position, + const char *title, const char *subtitle) +{ + werase(win_board); + box(win_board, 0, 0); + + alx_ncurses_title(win_board, title); + alx_ncurses_subtitle(win_board, subtitle); + board_loop_start(position); + wmove(win_board, 1 + position->row, 2 + 2 * position->col); + + wrefresh(win_board); +} + +static void board_loop_start(const struct Player_Iface_Position *position) +{ + ptrdiff_t k; + ptrdiff_t l; + int c; + + c = PLAYER_TUI_CHAR_HIDDEN_FIELD; + + for (ptrdiff_t i = 0; i < position->rows; i++) { + k = 1 + i; + + /* hidden */ + for (ptrdiff_t j = 0; j < position->cols; j++) { + l = 2 + 2 * j; + + show_char(k, l, c); + } + } + + /* Highlight cursor */ + if (position->highlight) + highlight_cursor(c, position); +} + +/* * * * * * * * * * + * * * Play * * * * * * + * * * * * * * * * */ +static void show_board (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position, + const char *title, const char *subtitle) +{ + + werase(win_board); + box(win_board, 0, 0); + + alx_ncurses_title(win_board, title); + alx_ncurses_subtitle(win_board, subtitle); + + board_loop(board, position); + wmove(win_board, 1 + position->row, 2 + 2 * position->col); + + wrefresh(win_board); +} + +static void board_loop (const struct Game_Iface_Out *board, + const struct Player_Iface_Position *position) +{ + ptrdiff_t k; + ptrdiff_t l; + int c; + + for (ptrdiff_t i = 0; i < board->rows; i++) { + k = 1 + i; + + /* clear */ + for (ptrdiff_t j = 0; j < board->cols; j++) { + l = 2 + 2 * j; + if (board->usr[i][j] == GAME_IFACE_USR_CLEAR) { + c = set_char(board->visible[i][j]); + show_char(k, l, c); + } + } + /* xyzzy */ + /* hidden */ + for (ptrdiff_t j = 0; j < board->cols; j++) { + l = 2 + 2 * j; + if (board->usr[i][j] != GAME_IFACE_USR_CLEAR) { + c = set_char(board->visible[i][j]); + show_char(k, l, c); + } + } + /* kboom */ + for (ptrdiff_t j = 0; j < board->cols; j++) { + l = 2 + 2 * j; + if (board->usr[i][j] == GAME_IFACE_USR_KBOOM) { + c = set_char(board->visible[i][j]); + show_char(k, l, c); + } + } + } + + /* Highlight cursor */ + if (position->highlight) { + c = set_char(board->visible[position->row][position->col]); + highlight_cursor(c, position); + } +} + +static void highlight_cursor(int c, + const struct Player_Iface_Position *position) +{ + ptrdiff_t k; + ptrdiff_t l; + int pair; + + k = 1 + position->row; + l = 2 + 2 * position->col; + + pair = PAIR_HILITE; + if (flag_color) + wattron(win_board, A_BOLD | COLOR_PAIR(pair)); + mvwaddch(win_board, k, l - 1, '<'); + mvwaddch(win_board, k, l, c); + mvwaddch(win_board, k, l + 1, '>'); + if (flag_color) + wattroff(win_board, A_BOLD | COLOR_PAIR(pair)); +} + +static int set_char (int tile) +{ + int c; + + switch (tile) { + case GAME_IFACE_VIS_KBOOM: + c = PLAYER_TUI_CHAR_KBOOM; + break; + case GAME_IFACE_VIS_HIDDEN_FIELD: + c = PLAYER_TUI_CHAR_HIDDEN_FIELD; + break; + case GAME_IFACE_VIS_HIDDEN_MINE: + c = PLAYER_TUI_CHAR_HIDDEN_MINE; + break; + case GAME_IFACE_VIS_HIDDEN_SAFE: + c = PLAYER_TUI_CHAR_HIDDEN_SAFE; + break; + case GAME_IFACE_VIS_SAFE_MINE: + c = PLAYER_TUI_CHAR_SAFE_MINE; + break; + case GAME_IFACE_VIS_0: + c = PLAYER_TUI_CHAR_0; + break; + case GAME_IFACE_VIS_1: + c = PLAYER_TUI_CHAR_1; + break; + case GAME_IFACE_VIS_2: + c = PLAYER_TUI_CHAR_2; + break; + case GAME_IFACE_VIS_3: + c = PLAYER_TUI_CHAR_3; + break; + case GAME_IFACE_VIS_4: + c = PLAYER_TUI_CHAR_4; + break; + case GAME_IFACE_VIS_5: + c = PLAYER_TUI_CHAR_5; + break; + case GAME_IFACE_VIS_6: + c = PLAYER_TUI_CHAR_6; + break; + case GAME_IFACE_VIS_7: + c = PLAYER_TUI_CHAR_7; + break; + case GAME_IFACE_VIS_8: + c = PLAYER_TUI_CHAR_8; + break; + case GAME_IFACE_VIS_FLAG: + c = PLAYER_TUI_CHAR_FLAG; + break; + case GAME_IFACE_VIS_FLAG_FALSE: + c = PLAYER_TUI_CHAR_FLAG_FALSE; + break; + case GAME_IFACE_VIS_POSSIBLE: + c = PLAYER_TUI_CHAR_POSSIBLE; + break; + case GAME_IFACE_VIS_POSSIBLE_FALSE: + c = PLAYER_TUI_CHAR_POSSIBLE_FALSE; + break; + default: + c = PLAYER_TUI_CHAR_ERROR; + break; + } + + return c; +} + +static void show_char (int row, int col, int c) +{ + int pair; + + switch (c) { + case PLAYER_TUI_CHAR_1: + pair = PAIR_1; + break; + case PLAYER_TUI_CHAR_2: + pair = PAIR_2; + break; + case PLAYER_TUI_CHAR_3: + pair = PAIR_3; + break; + case PLAYER_TUI_CHAR_4: + pair = PAIR_4; + break; + case PLAYER_TUI_CHAR_5: + pair = PAIR_5; + break; + case PLAYER_TUI_CHAR_6: + pair = PAIR_6; + break; + case PLAYER_TUI_CHAR_7: + pair = PAIR_7; + break; + case PLAYER_TUI_CHAR_8: + pair = PAIR_8; + break; + case PLAYER_TUI_CHAR_0: + pair = PAIR_BLANK; + break; + case PLAYER_TUI_CHAR_HIDDEN_MINE: + case PLAYER_TUI_CHAR_SAFE_MINE: + pair = PAIR_MINE; + break; + case PLAYER_TUI_CHAR_HIDDEN_FIELD: + case PLAYER_TUI_CHAR_HIDDEN_SAFE: + pair = PAIR_HIDDEN; + break; + case PLAYER_TUI_CHAR_POSSIBLE_FALSE: + pair = PAIR_fail; + break; + case PLAYER_TUI_CHAR_POSSIBLE: + pair = PAIR_POSSIBLE; + break; + case PLAYER_TUI_CHAR_FLAG_FALSE: + pair = PAIR_FAIL; + break; + case PLAYER_TUI_CHAR_FLAG: + pair = PAIR_FLAG; + break; + case PLAYER_TUI_CHAR_KBOOM: + pair = PAIR_KBOOM; + break; + default: + pair = PAIR_KBOOM; + break; + } + + if (flag_color) + wattron(win_board, A_BOLD | COLOR_PAIR(pair)); + mvwaddch(win_board, row, col - 1, ' '); + mvwaddch(win_board, row, col, c); + mvwaddch(win_board, row, col + 1, ' '); + if (flag_color) + wattroff(win_board, A_BOLD | COLOR_PAIR(pair)); +} + +/* * * * * * * * * * + * * * Input * * * * * * * + * * * * * * * * * */ +static int usr_input (void) +{ + int c; + int action; + + c = wgetch(win_board); + + switch (c) { + 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; + + /* ASCII 0x08 is BS */ + case KEY_BACKSPACE: + 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); + + c = wgetch(win_board); + if (c == 'y') { + c = wgetch(win_board); + if (c == 'z') { + c = wgetch(win_board); + if (c == 'z') { + c = wgetch(win_board); + if (c == '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; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (const struct Game_Iface_Out *board) +{ + + if (last_help == board->state) + return; + + 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; + } + + wrefresh(win_help); + last_help = board->state; +} + +static void show_help_start (void) +{ + int r; + int c; + + werase(win_help); + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c++, "Move:"); + /* hjkl */ + mvwaddch(win_help, r, c, 'h'); + c += 2; + mvwaddch(win_help, r, c, 'j'); + c += 2; + mvwaddch(win_help, r, c, 'k'); + c += 2; + mvwaddch(win_help, r, c, 'l'); + /* Arrows */ + r++; + c = 1; + mvwaddch(win_help, r, c, ACS_LARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_DARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_UARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_RARROW); + + r++; + c = 0; + mvwaddstr(win_help, r++, c, "Cursor:"); + mvwprintw(win_help, r++, c, " %c", 'c'); + + mvwaddstr(win_help, r++, c, "Step:"); + mvwprintw(win_help, r++, c, " Enter / %c", '+'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); + + wrefresh(win_help); + last_help = GAME_IFACE_STATE_FOO; +} + +static void show_help_play (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c++, "Move:"); + /* hjkl */ + mvwaddch(win_help, r, c, 'h'); + c += 2; + mvwaddch(win_help, r, c, 'j'); + c += 2; + mvwaddch(win_help, r, c, 'k'); + c += 2; + mvwaddch(win_help, r, c, 'l'); + /* Arrows */ + r++; + c = 1; + mvwaddch(win_help, r, c, ACS_LARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_DARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_UARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_RARROW); + + r++; + c = 0; + mvwaddstr(win_help, r++, c, "Cursor:"); + mvwprintw(win_help, r++, c, " %c", 'c'); + + mvwaddstr(win_help, r++, c, "Step:"); + mvwprintw(win_help, r++, c, " Enter / %c", '+'); + + mvwaddstr(win_help, r++, c, "Flag:"); + mvwprintw(win_help, r++, c, " Space"); + + mvwaddstr(win_help, r++, c, "Possible:"); + mvwprintw(win_help, r++, c, " %c", 'f'); + + mvwaddstr(win_help, r++, c, "rm flag:"); + mvwprintw(win_help, r++, c, " Backspace"); + + mvwaddstr(win_help, r++, c, "Pause:"); + mvwprintw(win_help, r++, c, " Break / %c", 'p'); + + mvwaddstr(win_help, r++, c, "Save:"); + mvwprintw(win_help, r++, c, " %c", 's'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + +static void show_help_pause (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c, "Cursor:"); + mvwprintw(win_help, r++, c, " %c", 'c'); + + mvwaddstr(win_help, r++, c, "Continue:"); + mvwprintw(win_help, r++, c, " Break / %c", 'p'); + + mvwaddstr(win_help, r++, c, "Save:"); + mvwprintw(win_help, r++, c, " %c", 's'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + +static void show_help_xyzzy (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c++, "XYZZY:"); + mvwprintw(win_help, r, c, "%c", '1'); + c += 2; + mvwprintw(win_help, r, c, "%c", '2'); +// c += 2; +// mvwprintw(win_help, r, c, "%c", 'd'); + + r++; + c = 0; + mvwaddstr(win_help, r++, c, "XYZZY off:"); + mvwprintw(win_help, r++, c, " %c", '0'); + + mvwaddstr(win_help, r++, c++, "Move:"); + /* hjkl */ + mvwaddch(win_help, r, c, 'h'); + c += 2; + mvwaddch(win_help, r, c, 'j'); + c += 2; + mvwaddch(win_help, r, c, 'k'); + c += 2; + mvwaddch(win_help, r, c, 'l'); + /* Arrows */ + r++; + c = 1; + mvwaddch(win_help, r, c, ACS_LARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_DARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_UARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_RARROW); + + r++; + c = 0; + mvwaddstr(win_help, r++, c, "Cursor:"); + mvwprintw(win_help, r++, c, " %c", 'c'); + + mvwaddstr(win_help, r++, c, "Step:"); + mvwprintw(win_help, r++, c, " Enter / %c", '+'); + + mvwaddstr(win_help, r++, c, "Flag:"); + mvwprintw(win_help, r++, c, " Space"); + + mvwaddstr(win_help, r++, c, "Possible:"); + mvwprintw(win_help, r++, c, " %c", 'f'); + + mvwaddstr(win_help, r++, c, "rm flag:"); + mvwprintw(win_help, r++, c, " Backspace"); + + mvwaddstr(win_help, r++, c, "Save:"); + mvwprintw(win_help, r++, c, " %c", 's'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + +static void show_help_cheat (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c++, "Move:"); + /* hjkl */ + mvwaddch(win_help, r, c, 'h'); + c += 2; + mvwaddch(win_help, r, c, 'j'); + c += 2; + mvwaddch(win_help, r, c, 'k'); + c += 2; + mvwaddch(win_help, r, c, 'l'); + /* Arrows */ + r++; + c = 1; + mvwaddch(win_help, r, c, ACS_LARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_DARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_UARROW); + c += 2; + mvwaddch(win_help, r, c, ACS_RARROW); + + r++; + c = 0; + mvwaddstr(win_help, r++, c, "Cursor:"); + mvwprintw(win_help, r++, c, " %c", 'c'); + + mvwaddstr(win_help, r++, c, "Step:"); + mvwprintw(win_help, r++, c, " Enter / %c", '+'); + + mvwaddstr(win_help, r++, c, "Flag:"); + mvwprintw(win_help, r++, c, " Space"); + + mvwaddstr(win_help, r++, c, "Possible:"); + mvwprintw(win_help, r++, c, " %c", 'f'); + + mvwaddstr(win_help, r++, c, "rm flag:"); + mvwprintw(win_help, r++, c, " Backspace"); + + mvwaddstr(win_help, r++, c, "Save:"); + mvwprintw(win_help, r++, c, " %c", 's'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + +static void show_help_safe (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c, "Save:"); + mvwprintw(win_help, r++, c, " %c", 's'); + + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + +static void show_help_gameover (void) +{ + int r; + int c; + + r = 0; + c = 0; + mvwaddstr(win_help, r++, c, "Quit:"); + mvwprintw(win_help, r++, c, " %c", 'q'); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/save/save.c b/src/save/save.c new file mode 100755 index 0000000..fb2ca22 --- /dev/null +++ b/src/save/save.c @@ -0,0 +1,238 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/save/save.h" + +#include +#include +#include + +#include + +#include "libalx/base/errno/perror.h" +#include "libalx/base/stdio/wait.h" + +#include "mine-sweeper/game/core.h" +#include "mine-sweeper/player/iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + char home_path [FILENAME_MAX]; + char user_game_path [FILENAME_MAX]; + char saved_path [FILENAME_MAX]; + char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void save_init (void) +{ + + if (snprintf(home_path, sizeof(home_path), "%s/", + getenv(ENV_HOME)) >= FILENAME_MAX) { + goto err_path; + } + if (snprintf(user_game_path, sizeof(user_game_path), "%s/%s/", + home_path, USER_GAME_DIR) >= FILENAME_MAX) { + goto err_path; + } + if (snprintf(saved_path, sizeof(saved_path), "%s/%s/", + home_path, USER_SAVED_DIR) >= FILENAME_MAX) { + goto err_path; + } + saved_name[0] = '\0'; + + if (mkdir(user_game_path, 0700)) { + if (errno != EEXIST) + goto err_mkdir; + } + if (mkdir(saved_path, 0700)) { + if (errno != EEXIST) + goto err_mkdir; + return; + } + + return; + +err_path: + alx_perror("Path is too large and has been truncated"); + exit(EXIT_FAILURE); +err_mkdir: + alx_perror(NULL); +} + +void save_clr (void) +{ + + if (snprintf(saved_path, sizeof(saved_path), "%s/%s/", + home_path, USER_SAVED_DIR) >= FILENAME_MAX) { + goto err_path; + } + + return; + + +err_path: + alx_perror("Path is too large and has been truncated"); + exit(EXIT_FAILURE); +} + +int load_game_file (void) +{ + char fname[FILENAME_MAX]; + FILE *fp; + int i; + int j; + + if (snprintf(fname, sizeof(fname), "%s/%s", + saved_path, saved_name) >= FILENAME_MAX) { + goto err_path; + } + + fp = fopen(fname, "r"); + if (!fp) + return -1; + fscanf(fp, "mine-sweeper saved game"); + fscanf(fp, " rows %ti", &game_board.rows); + fscanf(fp, " cols %ti", &game_board.cols); + fscanf(fp, " mines %i", &game_board.mines); + fscanf(fp, " gnd"); + for (i = 0; i < game_board.rows; i++) { + fscanf(fp, " %i", &game_board.gnd[i][0]); + for (j = 1; j < game_board.cols; j++) + fscanf(fp, ",%i", &game_board.gnd[i][j]); + } + fscanf(fp, " usr"); + for (i = 0; i < game_board.rows; i++) { + fscanf(fp, " %i", &game_board.usr[i][0]); + for (j = 1; j < game_board.cols; j++) + fscanf(fp, ",%i", &game_board.usr[i][j]); + } + fscanf(fp, " flags %i", &game_board.flags); + fscanf(fp, " cleared %i", &game_board.clr); + + fclose(fp); + + return 0; + + +err_path: + alx_perror("Path is too large and has been truncated"); + alx_wait4enter(); + exit(EXIT_FAILURE); +} + +void save_game_file (char fpath[static restrict FILENAME_MAX]) +{ + char fname[FILENAME_MAX]; + char tmp[FILENAME_MAX]; + char old_saved[FILENAME_MAX]; + char file_num[6]; + FILE *fp; + int i; + int j; + bool x; + + /* Don't change saved_name variable if not in default dir */ + if (fpath) + snprintf(old_saved, sizeof(old_saved), "%s", saved_name); + + /* Default path & name */ + save_clr(); + snprintf(saved_name, sizeof(saved_name), "%s", SAVED_NAME_DEFAULT); + file_num[0] = '\0'; + + /* Request file name */ + player_iface_save_name(fpath, saved_name); + + /* Look for an unused name of the type 'name_XXX.mine'. */ + x = true; + for (i = 0; x; i++) { + if (!fpath) { + if (snprintf(fname, sizeof(fname), "%s/%s%s%s", + saved_path, saved_name, file_num, + FILE_EXTENSION) >= FILENAME_MAX) { + goto err_path; + } + } else { + if (snprintf(fname, sizeof(fname), "%s/%s%s%s", + fpath, saved_name, file_num, + FILE_EXTENSION) >= FILENAME_MAX) { + goto err_path; + } + } + + fp = fopen(fname, "r"); + if (fp) { + fclose(fp); + file_num[0] = '_'; + file_num[1] = '0' + ((i / 100) % 10); + file_num[2] = '0' + ((i / 10) % 10); + file_num[3] = '0' + (i % 10); + file_num[4] = '\0'; + } else { + x = false; + if (snprintf(tmp, sizeof(tmp), "%s%s%s", + saved_name, file_num, + FILE_EXTENSION) >= FILENAME_MAX) { + goto err_path; + } + snprintf(saved_name, sizeof(saved_name), "%s", tmp); + } + } + + /* Write to a new file */ + fp = fopen(fname, "w"); + if (!fp) { + alx_perror(fname); + goto err_fopen; + } + fprintf(fp, "mine-sweeper saved game\n"); + fprintf(fp, "rows %ti\n", game_board.rows); + fprintf(fp, "cols %ti\n", game_board.cols); + fprintf(fp, "mines %i\n", game_board.mines); + fprintf(fp, "gnd\n"); + for (i = 0; i < game_board.rows; i++) { + fprintf(fp, "%i", game_board.gnd[i][0]); + for (j = 1; j < game_board.cols; j++) + fprintf(fp, ",%i", game_board.gnd[i][j]); + fprintf(fp, "\n"); + } + fprintf(fp, "usr\n"); + for (i = 0; i < game_board.rows; i++) { + fprintf(fp, "%i", game_board.usr[i][0]); + for (j = 1; j < game_board.cols; j++) + fprintf(fp, ",%i", game_board.usr[i][j]); + fprintf(fp, "\n"); + } + fprintf(fp, "flags %i\n", game_board.flags); + fprintf(fp, "cleared %i\n", game_board.clr); + + fclose(fp); +err_fopen: + /* Don't change saved_name if saving in non-default dir */ + if (fpath) + snprintf(saved_name, sizeof(saved_name), "%s", old_saved); + + return; + + +err_path: + alx_perror("Path is too large and has been truncated"); + alx_wait4enter(); + exit(EXIT_FAILURE); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/save/score.c b/src/save/score.c new file mode 100755 index 0000000..1deed1c --- /dev/null +++ b/src/save/score.c @@ -0,0 +1,128 @@ +/****************************************************************************** + * Copyright (C) 2015 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/save/score.h" + +#include +#include +#include +#include + +#include "libalx/base/errno/perror.h" +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/wait.h" + +#include "mine-sweeper/game/core.h" +#include "mine-sweeper/game/iface.h" +#include "mine-sweeper/player/iface.h" +#include "mine-sweeper/save/save.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void save_score (const struct Game_Iface_Score *game_iface_score) +{ + struct tm *date_format; + char *fname; + char player_name[BUFSIZ]; + FILE *fp; + time_t date_secs; + + /* File name */ + switch (game_iface_score->level) { + case GAME_IFACE_LVL_BEGINNER: + fname = HISCORES_BEGINNER_FILE; + break; + case GAME_IFACE_LVL_INTERMEDIATE: + fname = HISCORES_INTERMEDIATE_FILE; + break; + case GAME_IFACE_LVL_EXPERT: + fname = HISCORES_EXPERT_FILE; + break; + } + + /* Date & time */ + date_secs = time(NULL); + date_format = localtime(&date_secs); + + /* Player name (foo is default) */ + player_iface_score_name(player_name); + + /* Write to file (append) */ + errno = 0; + fp = fopen(fname, "a"); + if (!fp) + goto err_fp; + fprintf(fp, "\n"); + fprintf(fp, "name %s\n", player_name); + fprintf(fp, "date %i\n", (int)date_secs); + fprintf(fp, "{\n"); + fprintf(fp, " isdst %i\n", date_format->tm_isdst); + fprintf(fp, " yday %i\n", date_format->tm_yday); + fprintf(fp, " wday %i\n", date_format->tm_wday); + fprintf(fp, " year %i\n", date_format->tm_year); + fprintf(fp, " mon %i\n", date_format->tm_mon); + fprintf(fp, " mday %i\n", date_format->tm_mday); + fprintf(fp, " hour %i\n", date_format->tm_hour); + fprintf(fp, " min %i\n", date_format->tm_min); + fprintf(fp, " sec %i\n", date_format->tm_sec); + fprintf(fp, "}\n"); + fprintf(fp, "time %i\n", game_iface_score->time); + fprintf(fp, "clicks %i\n", game_iface_score->clicks); + fprintf(fp, "file %s\n", saved_name); + fclose(fp); + + return; + +err_fp: + alx_perror("Score could not be saved"); +} + +void print_scores (void) +{ + char cmd[_POSIX_ARG_MAX]; + + if (snprintf(cmd, sizeof(cmd), "less %s %s %s", + HISCORES_BEGINNER_FILE, + HISCORES_INTERMEDIATE_FILE, + HISCORES_EXPERT_FILE) >= SSIZEOF(cmd)) { + goto err; + } + if (system(cmd)) + alx_perror(NULL); + return; +err: + alx_perror("Path is too large and has been truncated"); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/xyzzy/xyzzy.c b/src/xyzzy/xyzzy.c new file mode 100755 index 0000000..8d2fcc8 --- /dev/null +++ b/src/xyzzy/xyzzy.c @@ -0,0 +1,108 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "mine-sweeper/xyzzy/xyzzy.h" + +#include + +#include "mine-sweeper/game/iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +static int x; +static bool step_notflag; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void xyzzy_step_all (const struct Game_Iface_Out *out, + struct Game_Iface_In *in); +static void xyzzy_flag_all (const struct Game_Iface_Out *out, + struct Game_Iface_In *in); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void xyzzy_init (void) +{ + + x = 0; + step_notflag = true; +} + +int xyzzy_lin (const struct Game_Iface_Out *out, + struct Game_Iface_In *in) +{ + + if (!x) + x = 1; + + if (step_notflag) { + xyzzy_step_all(out, in); + } else { + xyzzy_flag_all(out, in); + x--; + } + + step_notflag = !step_notflag; + + return x; +} + +int xyzzy_p (const struct Game_Iface_Out *out, + struct Game_Iface_In *in) +{ + + if (!x) + x = (out->rows * out->cols) / 2; + + xyzzy_lin(out, in); + + return x; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void xyzzy_step_all (const struct Game_Iface_Out *out, + struct Game_Iface_In *in) +{ + int i; + int j; + + for (i = 0; i < out->rows; i++) { + for (j = 0; j < out->cols; j++) { + if (out->usr[i][j] == GAME_IFACE_USR_CLEAR) + in->act_game[i][j] = GAME_IFACE_GAME_ACT_STEP; + } + } +} + +static void xyzzy_flag_all (const struct Game_Iface_Out *out, + struct Game_Iface_In *in) +{ + int i; + int j; + + for (i = 0; i < out->rows; i++) { + for (j = 0; j < out->cols; j++) { + if (out->usr[i][j] == GAME_IFACE_USR_CLEAR) + in->act_game[i][j] = GAME_IFACE_GAME_ACT_FLAG; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/tmp/Makefile b/tmp/Makefile old mode 100644 new mode 100755 index 363d0ca..4fb766e --- a/tmp/Makefile +++ b/tmp/Makefile @@ -1,74 +1,94 @@ -# -*- MakeFile -*- +#! /usr/bin/make -f -# MACRO = substitute with this +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ -# directories +################################################################################ +# dependencies + +OBJ = \ + main.o -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +MAIN_INC = \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(INC_DIR)/mine-sweeper/about/about.h \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/menu/parser.h \ + $(INC_DIR)/mine-sweeper/player/iface.h \ + $(INC_DIR)/mine-sweeper/save/save.h \ + $(INC_DIR)/mine-sweeper/save/score.h +MAIN_SRC = \ + $(SRC_DIR)/main.c -ABOUT_DIR = $(MODULES_DIR)/about/ -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -CTRL_DIR = $(MODULES_DIR)/ctrl/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ +# target: dependencies +# action -GAME_DIR = $(MODULES_DIR)/game/ -GAME_INC_DIR = $(GAME_DIR)/inc/ +PHONY := all +all: $(OBJ) about ctrl game menu player save xyzzy -MENU_DIR = $(MODULES_DIR)/menu/ -MENU_INC_DIR = $(MENU_DIR)/inc/ -PLAY_DIR = $(MODULES_DIR)/player/ -PLAY_INC_DIR = $(PLAY_DIR)/inc/ +PHONY += about +about: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -SAVE_DIR = $(MODULES_DIR)/save/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ +PHONY += ctrl +ctrl: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -SRC_DIR = $(MAIN_DIR)/src/ +PHONY += game +game: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -# dependencies +PHONY += menu +menu: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -ALL = main.o - -MAIN_INC_LIBALX = libalx/curses/alx_ncur.h -MAIN_INC_ABOUT = about.h -MAIN_INC_CTRL = start.h -MAIN_INC_GAME = game.h -MAIN_INC_MENU = parser.h menu_iface.h -MAIN_INC_PLAY = player_iface.h -MAIN_INC_SAVE = save.h score.h -MAIN_DEPS = $(SRC_DIR)/main.c \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MAIN_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MAIN_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MAIN_INC_CTRL)) \ - $(patsubst %,$(GAME_INC_DIR)/%,$(MAIN_INC_GAME)) \ - $(patsubst %,$(MENU_INC_DIR)/%,$(MAIN_INC_MENU)) \ - $(patsubst %,$(PLAY_INC_DIR)/%,$(MAIN_INC_PLAY)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MAIN_INC_SAVE)) -MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(GAME_INC_DIR) \ - -I $(MENU_INC_DIR) \ - -I $(PLAY_INC_DIR) \ - -I $(SAVE_INC_DIR) +PHONY += player +player: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ +PHONY += save +save: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -# target: dependencies -# action +PHONY += xyzzy +xyzzy: + @echo " MAKE tmp/$@" + $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -all: $(ALL) -main.s: $(MAIN_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ +main.s: $(MAIN_SRC) $(MAIN_INC) + @echo " CC mine-sweeper/tmp/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ main.o: main.s - @echo " AS $@" + @echo " AS mine-sweeper/tmp/$@" $(Q)$(AS) $< -o $@ +PHONY += clean clean: - $(Q)rm -f *.o *.s + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + ################################################################################ ######## End of file ########################################################### diff --git a/tmp/about/Makefile b/tmp/about/Makefile new file mode 100755 index 0000000..c0c86a2 --- /dev/null +++ b/tmp/about/Makefile @@ -0,0 +1,53 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + about.o + +ABOUT_INC = \ + $(INC_DIR)/mine-sweeper/about/about.h \ + $(LIBALX_INC_DIR)/libalx/base/errno/perror.h \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.h +ABOUT_SRC = \ + $(SRC_DIR)/about/about.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +about.s: $(ABOUT_SRC) $(ABOUT_INC) + @echo " CC mine-sweeper/about/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +about.o: about.s + @echo " AS mine-sweeper/about/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/ctrl/Makefile b/tmp/ctrl/Makefile new file mode 100755 index 0000000..638a870 --- /dev/null +++ b/tmp/ctrl/Makefile @@ -0,0 +1,55 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + start.o + +START_INC = \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/player/iface.h +START_SRC = \ + $(SRC_DIR)/ctrl/start.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +start.s: $(START_SRC) $(START_INC) + @echo " CC mine-sweeper/ctrl/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +start.o: start.s + @echo " AS mine-sweeper/ctrl/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/game/Makefile b/tmp/game/Makefile new file mode 100755 index 0000000..c0a1b85 --- /dev/null +++ b/tmp/game/Makefile @@ -0,0 +1,72 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + core.o \ + iface.o + +CORE_INC = \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/seed_mix.h \ + $(INC_DIR)/mine-sweeper/save/save.h +CORE_SRC = \ + $(SRC_DIR)/game/core.c + +IFACE_INC = \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/seed_mix.h \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(INC_DIR)/mine-sweeper/player/iface.h \ + $(INC_DIR)/mine-sweeper/save/save.h \ + $(INC_DIR)/mine-sweeper/save/score.h \ + $(INC_DIR)/mine-sweeper/xyzzy/xyzzy.h +IFACE_SRC = \ + $(SRC_DIR)/game/iface.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +core.s: $(CORE_SRC) $(CORE_INC) + @echo " CC mine-sweeper/game/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +core.o: core.s + @echo " AS mine-sweeper/game/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC mine-sweeper/game/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +iface.o: iface.s + @echo " AS mine-sweeper/game/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/menu/Makefile b/tmp/menu/Makefile new file mode 100755 index 0000000..be2b939 --- /dev/null +++ b/tmp/menu/Makefile @@ -0,0 +1,116 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + parser.o \ + clui.o \ + tui.o \ + iface.o + +PARSER_INC = \ + $(INC_DIR)/mine-sweeper/menu/parser.h \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/seed_mix.h \ + $(INC_DIR)/mine-sweeper/about/about.h \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/player/iface.h \ + $(INC_DIR)/mine-sweeper/save/save.h +PARSER_SRC = \ + $(SRC_DIR)/menu/parser.c + +CLUI_INC = \ + $(INC_DIR)/mine-sweeper/menu/clui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(INC_DIR)/mine-sweeper/about/about.h \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/save/save.h +CLUI_SRC = \ + $(SRC_DIR)/menu/clui.c + +TUI_INC = \ + $(INC_DIR)/mine-sweeper/menu/tui.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/menu.h \ + $(INC_DIR)/mine-sweeper/about/about.h \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/save/save.h \ + $(INC_DIR)/mine-sweeper/save/score.h +TUI_SRC = \ + $(SRC_DIR)/menu/tui.c + +IFACE_INC = \ + $(INC_DIR)/mine-sweeper/menu/iface.h \ + $(INC_DIR)/mine-sweeper/ctrl/start.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/menu/clui.h \ + $(INC_DIR)/mine-sweeper/menu/tui.h +IFACE_SRC = \ + $(SRC_DIR)/menu/iface.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +parser.s: $(PARSER_SRC) $(PARSER_INC) + @echo " CC mine-sweeper/menu/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +parser.o: parser.s + @echo " AS mine-sweeper/menu/$@" + $(Q)$(AS) $< -o $@ + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC mine-sweeper/menu/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +clui.o: clui.s + @echo " AS mine-sweeper/menu/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC mine-sweeper/menu/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +tui.o: tui.s + @echo " AS mine-sweeper/menu/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC mine-sweeper/menu/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +iface.o: iface.s + @echo " AS mine-sweeper/menu/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/player/Makefile b/tmp/player/Makefile new file mode 100755 index 0000000..b99d03a --- /dev/null +++ b/tmp/player/Makefile @@ -0,0 +1,86 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + clui.o \ + tui.o \ + iface.o + +CLUI_INC = \ + $(INC_DIR)/mine-sweeper/player/clui.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/player/iface.h +CLUI_SRC = \ + $(SRC_DIR)/player/clui.c + +TUI_INC = \ + $(INC_DIR)/mine-sweeper/player/tui.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/player/iface.h +TUI_SRC = \ + $(SRC_DIR)/player/tui.c + +IFACE_INC = \ + $(INC_DIR)/mine-sweeper/player/iface.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/player/clui.h \ + $(INC_DIR)/mine-sweeper/player/tui.h +IFACE_SRC = \ + $(SRC_DIR)/player/iface.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC mine-sweeper/player/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +clui.o: clui.s + @echo " AS mine-sweeper/player/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC mine-sweeper/player/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +tui.o: tui.s + @echo " AS mine-sweeper/player/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC mine-sweeper/player/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +iface.o: iface.s + @echo " AS mine-sweeper/player/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/save/Makefile b/tmp/save/Makefile new file mode 100755 index 0000000..722172b --- /dev/null +++ b/tmp/save/Makefile @@ -0,0 +1,74 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + save.o \ + score.o + +SAVE_INC = \ + $(INC_DIR)/mine-sweeper/save/save.h \ + $(LIBALX_INC_DIR)/libalx/base/errno/perror.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(INC_DIR)/mine-sweeper/player/iface.h +SAVE_SRC = \ + $(SRC_DIR)/save/save.c + +SCORE_INC = \ + $(INC_DIR)/mine-sweeper/save/score.h \ + $(LIBALX_INC_DIR)/libalx/base/errno/perror.h \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/mine-sweeper/game/core.h \ + $(INC_DIR)/mine-sweeper/game/iface.h \ + $(INC_DIR)/mine-sweeper/player/iface.h +SCORE_SRC = \ + $(SRC_DIR)/save/score.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +save.s: $(SAVE_SRC) $(SAVE_INC) + @echo " CC mine-sweeper/save/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +save.o: save.s + @echo " AS mine-sweeper/save/$@" + $(Q)$(AS) $< -o $@ + +score.s: $(SCORE_SRC) $(SCORE_INC) + @echo " CC mine-sweeper/save/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +score.o: score.s + @echo " AS mine-sweeper/save/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/xyzzy/Makefile b/tmp/xyzzy/Makefile new file mode 100755 index 0000000..bc0a015 --- /dev/null +++ b/tmp/xyzzy/Makefile @@ -0,0 +1,52 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + xyzzy.o + +XYZZY_INC = \ + $(INC_DIR)/mine-sweeper/xyzzy/xyzzy.h \ + $(INC_DIR)/mine-sweeper/game/iface.h +XYZZY_SRC = \ + $(SRC_DIR)/xyzzy/xyzzy.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +xyzzy.s: $(XYZZY_SRC) $(XYZZY_INC) + @echo " CC mine-sweeper/xyzzy/$@" + $(Q)$(CC) $(CFLAGS) -S $< -o $@ +xyzzy.o: xyzzy.s + @echo " AS mine-sweeper/xyzzy/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/var/hiscores/hiscores_beginner.mine b/var/hiscores/hiscores_beginner.mine deleted file mode 100644 index 57b227d..0000000 --- a/var/hiscores/hiscores_beginner.mine +++ /dev/null @@ -1 +0,0 @@ -beginner times diff --git a/var/hiscores/hiscores_expert.mine b/var/hiscores/hiscores_expert.mine deleted file mode 100644 index 88ef3bf..0000000 --- a/var/hiscores/hiscores_expert.mine +++ /dev/null @@ -1 +0,0 @@ -expert times diff --git a/var/hiscores/hiscores_intermediate.mine b/var/hiscores/hiscores_intermediate.mine deleted file mode 100644 index a1fd0ca..0000000 --- a/var/hiscores/hiscores_intermediate.mine +++ /dev/null @@ -1 +0,0 @@ -intermediate times diff --git a/var/mine-sweeper/hiscores/beginner.mine b/var/mine-sweeper/hiscores/beginner.mine new file mode 100755 index 0000000..57b227d --- /dev/null +++ b/var/mine-sweeper/hiscores/beginner.mine @@ -0,0 +1 @@ +beginner times diff --git a/var/mine-sweeper/hiscores/expert.mine b/var/mine-sweeper/hiscores/expert.mine new file mode 100755 index 0000000..88ef3bf --- /dev/null +++ b/var/mine-sweeper/hiscores/expert.mine @@ -0,0 +1 @@ +expert times diff --git a/var/mine-sweeper/hiscores/intermediate.mine b/var/mine-sweeper/hiscores/intermediate.mine new file mode 100755 index 0000000..a1fd0ca --- /dev/null +++ b/var/mine-sweeper/hiscores/intermediate.mine @@ -0,0 +1 @@ +intermediate times -- cgit v1.2.3