Compare commits

..

11 Commits

Author SHA1 Message Date
nakidai 21e1f14990 Merge pull request 'Add configure' (#1) from configure into master
Reviewed-on: https://nakidai.ddns.net/nakidai/csnake/pulls/1
2023-10-30 21:57:11 +03:00
Nakidai e9e503d5b2
Change length of line to SIZE*2 2023-10-30 15:52:25 +03:00
Nakidai f25cd3ca01
Some changes
- Move config.h to include/
- Move config.mk to root
- Remove $RM from configure
2023-10-30 15:50:54 +03:00
Nakidai f2e33ad320
Add help 2023-10-30 15:50:54 +03:00
Nakidai 9529eebcbc
Fix configure 2023-10-30 15:50:53 +03:00
Nakidai 2e05977e12
Autocreate config dir attempt 2 2023-10-30 15:50:53 +03:00
Nakidai 5f6fc8f212
Autocreate config dir 2023-10-30 15:50:53 +03:00
Nakidai 317622a253
Add code configuraction in configure 2023-10-30 15:50:53 +03:00
Nakidai b23325bfec
Remove config from make clean 2023-10-30 15:50:53 +03:00
Nakidai 94d6a769a1
Move config to config/ 2023-10-30 15:50:53 +03:00
Nakidai 2ebe6fccea
Add configure for make 2023-10-30 15:50:52 +03:00
5 changed files with 57 additions and 10 deletions

View File

@ -1,9 +1,6 @@
OUT = game include config.mk
CFLAGS =
LDFLAGS =
INCLUDE = -Iinclude INCLUDE = -Iinclude
CC = cc
LD = ld
RM = rm -f RM = rm -f
SRCDIR = src SRCDIR = src
OBJDIR = obj OBJDIR = obj

4
config.mk Normal file
View File

@ -0,0 +1,4 @@
CC = cc
CFLAGS =
LDFLAGS =
OUT = game

42
configure vendored Executable file
View File

@ -0,0 +1,42 @@
#!/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}
CFLAGS=${CFLAGS:-}
LDFLAGS=${LDFLAGS:-}
OUT=${OUT:-game}
SIZE=${SIZE:-10}
DEFX=${DEFX:-0}
DEFY=${DEFY:-0}
echo "Makefile configuration:"
echo "Compiler: $CC"
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
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
OUT = $OUT" > config.mk
echo "#define SIZE $SIZE
#define DEFX $DEFX
#define DEFY $DEFY" > include/config.h

3
include/config.h Normal file
View File

@ -0,0 +1,3 @@
#define SIZE 10
#define DEFX 0
#define DEFY 0

View File

@ -8,6 +8,7 @@
#include "screen.h" #include "screen.h"
#include "player.h" #include "player.h"
#include "food.h" #include "food.h"
#include "config.h"
void drawPlayer(Player *player, Screen *screen) void drawPlayer(Player *player, Screen *screen)
{ {
@ -21,7 +22,7 @@ Food generateFood(Player *player)
Food food; Food food;
do do
{ {
food = (Food){random() % 10, random() % 10}; food = (Food){random() % SIZE, random() % SIZE};
} while (playerCheckFoodCollision(player, food)); } while (playerCheckFoodCollision(player, food));
return food; return food;
} }
@ -34,8 +35,8 @@ void resetCoordinates(void)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
srandom(time(NULL)); srandom(time(NULL));
Player *player = playerCreate(DOWN, 0, 0, 0); Player *player = playerCreate(DOWN, DEFX, DEFY, 0);
Screen *screen = screenCreate(10, 10, ' '); Screen *screen = screenCreate(SIZE, SIZE, ' ');
PlayerNode *node; PlayerNode *node;
thrd_t input_thread; thrd_t input_thread;
int i; int i;
@ -72,7 +73,7 @@ int main(int argc, char **argv)
} }
head_x = player->head->x; head_x = player->head->x;
head_y = player->head->y; 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; *running = false;
break; break;
@ -83,7 +84,7 @@ int main(int argc, char **argv)
*screenGetPoint(screen, food.x, food.y) = '@'; *screenGetPoint(screen, food.x, food.y) = '@';
resetCoordinates(); resetCoordinates();
screenShow(screen); screenShow(screen);
for (i = 0; i < 20; ++i) putchar('-'); for (i = 0; i < SIZE*2; ++i) putchar('-');
printf("\nScore: %d\n", player->score); printf("\nScore: %d\n", player->score);
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); thrd_sleep(&(struct timespec){.tv_sec=1}, NULL);