From 3bb91c82acb1dc76b102160caef9d0929c6fa2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Krej=C4=8D=C3=AD?= Date: Mon, 26 Jul 2021 12:33:54 +0200 Subject: [PATCH] logik : add a brand new game logik is also known as mastermind. There is an optionnal flag to compile with : `make logik COLORMODE=BGCOLOR` **NOTE** : only tested on FreeBSD, it suppose to work on UNIX-like. One of the needed dependency is : ``` /bin/stty raw /bin/stty cooked ``` it's hard coded in the line 75, 134 and 140. --- Makefile | 7 ++- README.md | 1 + logik.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ man/logik.6 | 29 ++++++++++ 4 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 logik.c create mode 100644 man/logik.6 diff --git a/Makefile b/Makefile index 7284d88..9634798 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,9 @@ MAN_DIR?=/usr/share/man/man6 CFLAGS+= -Wno-unused-result -D SCORES_DIR=\"$(SCORES_DIR)\" LDFLAGS+= -lncurses -lm +COLORMODE:=FGCOLOR -ALL= jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare darrt snakeduel +ALL= jewels sudoku mines reversi checkers battleship rabbithole sos pipes fifteen memoblocks fisher muncher miketron redsquare darrt snakeduel logik SCORE_FILES= pipes_scores jewels_scores miketron_scores muncher_scores fisher_scores darrt_scores all: $(ALL) @@ -53,9 +54,11 @@ redsquare: redsquare.c config.h $(CC) redsquare.c $(LDFLAGS) $(CFLAGS) -o ./redsquare darrt: darrt.c config.h common.h $(CC) darrt.c $(LDFLAGS) $(CFLAGS) -o ./darrt - snakeduel: snakeduel.c config.h $(CC) snakeduel.c $(LDFLAGS) $(CFLAGS) -o ./snakeduel +logik: logik.c + $(CC) $@.c -o $@ -D$(COLORMODE) + clean: rm $(ALL) uninstall: diff --git a/README.md b/README.md index 0789f94..f8b6328 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The games include: * Redsquare (Conway's Game of Life made playable!) * Darrt (with original gameplay!) * Snakeduel +* Logik (or also known as Mastermind) The difficulty and/or dimensions are adjustable through simple command line options, you can play a minesweeper game that take hours to complete, or exprience hexadecimal sudoku and 8x8 fifteen-like puzzles! diff --git a/logik.c b/logik.c new file mode 100644 index 0000000..2607528 --- /dev/null +++ b/logik.c @@ -0,0 +1,148 @@ +#include +#include +#include +#include + + +#define NBHOLES 5 +#define NBLINES 10 +#define NBCOLORS 8 +#define NBMINUS 5 +unsigned char pion[] = "rgypmRGY"; + +int +convert(unsigned char a) { + + for(int i=0; i 0 ) { + inc[i] = convert(c); + i++; + stop = 0; + } + if( i > 0 & c == 'x' ) { /*aimed to backspace*/ + i--; + printf("\b"); + stop = 0; + } + if( c == 'Q' ) { + stop++; + if( stop == 2) + break; + } + } + printf("\t"); + + if( stop == 2 ) + break; + + black=0; white=0; + /* black section : x : is in the right place */ + for(int i=0; i 0) & (tmp[i] > 0) ) { + if( tmp[i] <= mix[i] ) + white += tmp[i]; + else if ( mix[i] < tmp[i] ) + white += mix[i]; + } + + /* fmt */ + for(int i=0; i < NBHOLES - white ; i++) + printf("-"); + + for(int i=0; i < black; i++) + printf("x"); + + for(int i=0; i < white - black; i++) + printf("o"); + + if( black == 5 ) { + system("/bin/stty cooked"); + printf("\n\tYOU WIN\n"); + return 0; + } + for(int i=0; i