From 2ebe6fcceae1cb851c441823d4965774445bc194 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 02:33:30 +0300 Subject: [PATCH 01/10] Add configure for make --- .gitignore | 1 + Makefile | 2 +- configure | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 configure diff --git a/.gitignore b/.gitignore index 0fd9bb7..1c154dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ obj/ game +config.mk diff --git a/Makefile b/Makefile index e93e1de..0fd3380 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,6 @@ $(OUT): obj $(OBJ) $(CC) -o $@ $(OBJ) $(LDFLAGS) clean: - $(RM) $(OUT) $(OBJDIR)/* + $(RM) $(OUT) config.mk $(OBJDIR)/* .PHONY: default clean diff --git a/configure b/configure new file mode 100755 index 0000000..071c032 --- /dev/null +++ b/configure @@ -0,0 +1,19 @@ +#!/bin/sh + +CC=${CC:-cc} +RM=${RM:-rm -f} +CFLAGS=${CFLAGS:-} +LDFLAGS=${LDFLAGS:-} +OUT=${OUT:-game} + +echo "Compiler: $CC" +echo "Remove: $RM" +echo "CFLAGS: $CFLAGS" +echo "LDFLAGS: $LDFLAGS" +echo "Out file: $OUT" + +echo "CC = $CC +RM = $RM +CFLAGS = $CFLAGS +LDFLAGS = $LDFLAGS +OUT = $OUT" > config.mk From 94d6a769a154a8a6d3820b0643c84b79113f37f1 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:00:39 +0300 Subject: [PATCH 02/10] Move config to config/ --- .gitignore | 2 +- Makefile | 4 +++- configure | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1c154dc..e17cc81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ obj/ game -config.mk +config/ diff --git a/Makefile b/Makefile index 0fd3380..799d6bd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +include config/config.mk + OUT = game CFLAGS = LDFLAGS = @@ -22,6 +24,6 @@ $(OUT): obj $(OBJ) $(CC) -o $@ $(OBJ) $(LDFLAGS) clean: - $(RM) $(OUT) config.mk $(OBJDIR)/* + $(RM) $(OUT) config/* $(OBJDIR)/* .PHONY: default clean diff --git a/configure b/configure index 071c032..3b726f4 100755 --- a/configure +++ b/configure @@ -5,6 +5,7 @@ RM=${RM:-rm -f} CFLAGS=${CFLAGS:-} LDFLAGS=${LDFLAGS:-} OUT=${OUT:-game} +SIZE=${SIZE:-10} echo "Compiler: $CC" echo "Remove: $RM" @@ -16,4 +17,4 @@ echo "CC = $CC RM = $RM CFLAGS = $CFLAGS LDFLAGS = $LDFLAGS -OUT = $OUT" > config.mk +OUT = $OUT" > config/config.mk From b23325bfec0d16b9b30033cc38eeadc07230a4b1 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:05:29 +0300 Subject: [PATCH 03/10] Remove config from make clean --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 799d6bd..d3e229f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config/config.mk OUT = game CFLAGS = LDFLAGS = -INCLUDE = -Iinclude +INCLUDE = -Iinclude -Iconfig CC = cc LD = ld RM = rm -f @@ -24,6 +24,6 @@ $(OUT): obj $(OBJ) $(CC) -o $@ $(OBJ) $(LDFLAGS) clean: - $(RM) $(OUT) config/* $(OBJDIR)/* + $(RM) $(OUT) $(OBJDIR)/* .PHONY: default clean From 317622a2531d1249cebed7b2ee46d26cea4394fd Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:09:32 +0300 Subject: [PATCH 04/10] Add code configuraction in configure --- configure | 12 ++++++++++++ src/main.c | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 3b726f4..83ad3df 100755 --- a/configure +++ b/configure @@ -6,15 +6,27 @@ CFLAGS=${CFLAGS:-} LDFLAGS=${LDFLAGS:-} OUT=${OUT:-game} SIZE=${SIZE:-10} +DEFX=${DEFX:-0} +DEFY=${DEFY:-0} +echo "Makefile configuration:" echo "Compiler: $CC" echo "Remove: $RM" echo "CFLAGS: $CFLAGS" echo "LDFLAGS: $LDFLAGS" echo "Out file: $OUT" +echo +echo "Code configuration:" +echo "Size: $SIZE" +echo "Start x: $DEFX" +echo "Start y: $DEFY" echo "CC = $CC RM = $RM CFLAGS = $CFLAGS LDFLAGS = $LDFLAGS OUT = $OUT" > config/config.mk + +echo "#define SIZE $SIZE +#define DEFX $DEFX +#define DEFY $DEFY" > config/config.h diff --git a/src/main.c b/src/main.c index 570ad51..eb17550 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,7 @@ #include "screen.h" #include "player.h" #include "food.h" +#include "config.h" void drawPlayer(Player *player, Screen *screen) { @@ -21,7 +22,7 @@ Food generateFood(Player *player) Food food; do { - food = (Food){random() % 10, random() % 10}; + food = (Food){random() % SIZE, random() % SIZE}; } while (playerCheckFoodCollision(player, food)); return food; } @@ -34,8 +35,8 @@ void resetCoordinates(void) int main(int argc, char **argv) { srandom(time(NULL)); - Player *player = playerCreate(DOWN, 0, 0, 0); - Screen *screen = screenCreate(10, 10, ' '); + Player *player = playerCreate(DOWN, DEFX, DEFY, 0); + Screen *screen = screenCreate(SIZE, SIZE, ' '); PlayerNode *node; thrd_t input_thread; int i; @@ -72,7 +73,7 @@ int main(int argc, char **argv) } head_x = player->head->x; head_y = player->head->y; - if (head_x >= 10 || head_x < 0 || head_y >= 10 || head_y < 0) + if (head_x >= SIZE || head_x < 0 || head_y >= SIZE || head_y < 0) { *running = false; break; From 5f6fc8f21257dce40db6ab467297dbfdd5d104eb Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:10:21 +0300 Subject: [PATCH 05/10] Autocreate config dir --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index 83ad3df..b3249d6 100755 --- a/configure +++ b/configure @@ -1,5 +1,7 @@ #!/bin/sh +mkdir config + CC=${CC:-cc} RM=${RM:-rm -f} CFLAGS=${CFLAGS:-} From 2e05977e12d4f8e076d46fe4cca9e187b0daa163 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:15:24 +0300 Subject: [PATCH 06/10] Autocreate config dir attempt 2 --- configure | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/configure b/configure index b3249d6..d49594e 100755 --- a/configure +++ b/configure @@ -1,7 +1,5 @@ #!/bin/sh -mkdir config - CC=${CC:-cc} RM=${RM:-rm -f} CFLAGS=${CFLAGS:-} @@ -23,6 +21,13 @@ echo "Size: $SIZE" echo "Start x: $DEFX" echo "Start y: $DEFY" +if [ ! test -d config ]; then + if [ test-f config ]; then + rm config + fi + mkdir config +fi + echo "CC = $CC RM = $RM CFLAGS = $CFLAGS From 9529eebcbcac1d27dace5c2951133ea7d48c9f8a Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:17:54 +0300 Subject: [PATCH 07/10] Fix configure --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index d49594e..1daeb23 100755 --- a/configure +++ b/configure @@ -21,8 +21,8 @@ echo "Size: $SIZE" echo "Start x: $DEFX" echo "Start y: $DEFY" -if [ ! test -d config ]; then - if [ test-f config ]; then +if ! test -d config; then + if test -f config; then rm config fi mkdir config From f2e33ad320822149ca52b30d4de2fc59a0ffa28d Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 03:27:47 +0300 Subject: [PATCH 08/10] Add help --- configure | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/configure b/configure index 1daeb23..04228a3 100755 --- a/configure +++ b/configure @@ -1,5 +1,18 @@ #!/bin/sh +if [[ "$*" == *"--help"* ]] || [[ "$*" == *"-h"* ]] +then + echo "Use environment variables to pass values: + CC - compiler (default: cc) + CFLAGS - flags for compiler + LDFLAGS - flags for linker + OUT - out file (default: game + SIZE - size of game field + DEFX - start x + DEFY - start y" + exit 1 +fi + CC=${CC:-cc} RM=${RM:-rm -f} CFLAGS=${CFLAGS:-} From f25cd3ca01f2891f2cf642b19cc2f0d160a5fc26 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 15:50:12 +0300 Subject: [PATCH 09/10] Some changes - Move config.h to include/ - Move config.mk to root - Remove $RM from configure --- .gitignore | 1 - Makefile | 9 ++------- config.mk | 4 ++++ configure | 14 ++------------ include/config.h | 3 +++ 5 files changed, 11 insertions(+), 20 deletions(-) create mode 100644 config.mk create mode 100644 include/config.h diff --git a/.gitignore b/.gitignore index e17cc81..0fd9bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ obj/ game -config/ diff --git a/Makefile b/Makefile index d3e229f..48a69b6 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,6 @@ -include config/config.mk +include config.mk -OUT = game -CFLAGS = -LDFLAGS = -INCLUDE = -Iinclude -Iconfig -CC = cc -LD = ld +INCLUDE = -Iinclude RM = rm -f SRCDIR = src OBJDIR = obj diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..eff6dc2 --- /dev/null +++ b/config.mk @@ -0,0 +1,4 @@ +CC = cc +CFLAGS = +LDFLAGS = +OUT = game diff --git a/configure b/configure index 04228a3..0843f06 100755 --- a/configure +++ b/configure @@ -14,7 +14,6 @@ then fi CC=${CC:-cc} -RM=${RM:-rm -f} CFLAGS=${CFLAGS:-} LDFLAGS=${LDFLAGS:-} OUT=${OUT:-game} @@ -24,7 +23,6 @@ DEFY=${DEFY:-0} echo "Makefile configuration:" echo "Compiler: $CC" -echo "Remove: $RM" echo "CFLAGS: $CFLAGS" echo "LDFLAGS: $LDFLAGS" echo "Out file: $OUT" @@ -34,19 +32,11 @@ echo "Size: $SIZE" echo "Start x: $DEFX" echo "Start y: $DEFY" -if ! test -d config; then - if test -f config; then - rm config - fi - mkdir config -fi - echo "CC = $CC -RM = $RM CFLAGS = $CFLAGS LDFLAGS = $LDFLAGS -OUT = $OUT" > config/config.mk +OUT = $OUT" > config.mk echo "#define SIZE $SIZE #define DEFX $DEFX -#define DEFY $DEFY" > config/config.h +#define DEFY $DEFY" > include/config.h diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..061c7be --- /dev/null +++ b/include/config.h @@ -0,0 +1,3 @@ +#define SIZE 10 +#define DEFX 0 +#define DEFY 0 From e9e503d5b25defe5291682a6203484564505bcdf Mon Sep 17 00:00:00 2001 From: Nakidai Date: Mon, 30 Oct 2023 15:52:25 +0300 Subject: [PATCH 10/10] Change length of line to SIZE*2 --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index eb17550..c24827c 100644 --- a/src/main.c +++ b/src/main.c @@ -84,7 +84,7 @@ int main(int argc, char **argv) *screenGetPoint(screen, food.x, food.y) = '@'; resetCoordinates(); screenShow(screen); - for (i = 0; i < 20; ++i) putchar('-'); + for (i = 0; i < SIZE*2; ++i) putchar('-'); printf("\nScore: %d\n", player->score); thrd_sleep(&(struct timespec){.tv_sec=1}, NULL);