diff options
author | Louie S <louie@example.com> | 2022-12-09 16:20:47 -0800 |
---|---|---|
committer | Louie Shprung <lshprung@scu.edu> | 2022-12-10 16:38:00 -0800 |
commit | 86c818d83e2ccf91efed4fcffd49ed3a5d44a173 (patch) | |
tree | d3c98b85cbc8b1f02138fd4e7250e6411eb9cbcd /src | |
parent | d0c84fc07e29ef8b4abb390831ddb71e5bd220cf (diff) |
Replace crude Makefile with Autotools build system
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/Makefile.in | 574 | ||||
-rw-r--r-- | src/body.c | 189 | ||||
-rw-r--r-- | src/draw.c | 277 |
4 files changed, 1043 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..eef8b12 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,3 @@ +bin_PROGRAMS = simple_snake +simple_snake_SOURCES = body.c draw.c body.h +simple_snake_LDADD = -lncurses -lm diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..223fedd --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,574 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = simple_snake$(EXEEXT) +subdir = src +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_simple_snake_OBJECTS = body.$(OBJEXT) draw.$(OBJEXT) +simple_snake_OBJECTS = $(am_simple_snake_OBJECTS) +simple_snake_DEPENDENCIES = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/body.Po ./$(DEPDIR)/draw.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(simple_snake_SOURCES) +DIST_SOURCES = $(simple_snake_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +simple_snake_SOURCES = body.c draw.c body.h +simple_snake_LDADD = -lncurses -lm +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +simple_snake$(EXEEXT): $(simple_snake_OBJECTS) $(simple_snake_DEPENDENCIES) $(EXTRA_simple_snake_DEPENDENCIES) + @rm -f simple_snake$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(simple_snake_OBJECTS) $(simple_snake_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/body.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/draw.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/body.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/body.Po + -rm -f ./$(DEPDIR)/draw.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-tags \ + distdir dvi dvi-am html html-am info info-am install \ + install-am install-binPROGRAMS install-data install-data-am \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binPROGRAMS + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/body.c b/src/body.c new file mode 100644 index 0000000..bfee083 --- /dev/null +++ b/src/body.c @@ -0,0 +1,189 @@ +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> + +#include "../include/body.h" + +typedef struct node{ + int x; + int y; + struct node *next; +} NODE; + +typedef struct snake{ + NODE *head; //"head" will be the physical tail of the snake + NODE *tail; //"tail" will be the physical head of the snake + int length; +} SNAKE; + +//private prototypes +NODE *makeNode(int x, int y); +void deleteNode(NODE *np); +void increaseSnake(SNAKE *sp); + +//public functions +SNAKE *makeSnake(int startx, int starty, int len){ + SNAKE *new = malloc(sizeof(SNAKE)); + NODE *np; + + assert(new != NULL); + + new->length = len; + + new->head = makeNode(startx-len+1, starty); + np = new->head; + len--; + + while(len > 0){ + np->next = makeNode(startx-len+1, starty); + np = np->next; + len--; + } + + new->tail = np; + + return new; +} + +void deleteSnake(SNAKE *sp){ + NODE *hold; + + if(sp != NULL){ + while(sp->head != NULL){ + hold = sp->head; + sp->head = sp->head->next; + deleteNode(hold); + } + } + + free(sp); + return; +} + +void updateSnake(SNAKE *sp, int dir, int maxx, int maxy, bool *collision, int *fruit_loc, bool *fruit, int *score){ + NODE *np; + + if(sp == NULL) return; + + //move the "back" to the "front" (note that sp->tail will not be set until after np->x and np->y are set) + np = sp->head; + sp->head = sp->head->next; + sp->tail->next = np; + np->next = NULL; + + //dir decides direction the snake is moving + switch(dir){ + case(0): //snake is moving up + np->x = sp->tail->x; + np->y = sp->tail->y-1; + break; + + case(1): //snake is moving right + np->x = sp->tail->x+1; + np->y = sp->tail->y; + break; + + case(2): //snake is moving down + np->x = sp->tail->x; + np->y = sp->tail->y+1; + break; + + case(3): //snake is moving left + np->x = sp->tail->x-1; + np->y = sp->tail->y; + } + + //update tail pointer + sp->tail = np; + + //check if eating fruit + if(*fruit && sp->tail->x == *fruit_loc && sp->tail->y == *(fruit_loc + 1)){ + *fruit = false; + (*score)++; + + //need to increase snake size + increaseSnake(sp); + } + + //check collision + *collision = checkSnake(sp, maxx, maxy); + + return; +} + +//true = collision, false = no collision +bool checkSnake(SNAKE *sp, int maxx, int maxy){ + NODE *np; + + if(sp == NULL) return true; + + //check if oob + if(sp->tail->x < 0 || sp->tail->x >= maxx || sp->tail->y < 0 || sp->tail->y >= maxy) return true; + + //check if collision with body (check each cell) + np = sp->head; + while(np != sp->tail && np != NULL){ + if(sp->tail->x == np->x && sp->tail->y == np->y) return true; + np = np->next; + } + + return false; +} + +int getSnakeTailx(SNAKE *sp){ + + if(sp != NULL && sp->tail != NULL) return sp->tail->x; + return -1; + +} +int getSnakeTaily(SNAKE *sp){ + + if(sp != NULL && sp->tail != NULL) return sp->tail->y; + return -1; + +} + +int getSnakeHeadx(SNAKE *sp){ + + if(sp != NULL && sp->head != NULL) return sp->head->x; + return -1; + +} + +int getSnakeHeady(SNAKE *sp){ + + if(sp != NULL && sp->head != NULL) return sp->head->y; + return -1; + +} + +//private functions +NODE *makeNode(int x, int y){ + NODE *new = malloc(sizeof(NODE)); + assert(new != NULL); + + new->x = x; + new->y = y; + new->next = NULL; + + return new; +} + +void deleteNode(NODE *np){ + + if(np != NULL) free(np); + + return; +} + +void increaseSnake(SNAKE *sp){ + int xdiff = sp->head->next->x - sp->head->x; + int ydiff = sp->head->next->y - sp->head->y; + NODE *new = makeNode(sp->head->x - xdiff, sp->head->y - ydiff); + + new->next = sp->head; + sp->head = new; + sp->length++; + + return; +} diff --git a/src/draw.c b/src/draw.c new file mode 100644 index 0000000..4926f04 --- /dev/null +++ b/src/draw.c @@ -0,0 +1,277 @@ +#include <errno.h> +#include <math.h> +#include <ncurses.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <time.h> +#include <unistd.h> + +#include "../include/body.h" + +#define START_SIZE 4 +//TODO consider having speed be affected by window size +#define SPEED 50000 //global refresh rate (for usleep()) +#define TIMEOUT 1 + +//#define DEBUG 1 + +void updateScore(int which, int score); +void updateScreen(SNAKE *sp, int dir, bool *collision, int *fruit_loc, bool *fruit, int *score); +int loadScore(void); +void saveScore(int highscore); + +#ifdef DEBUG +void count_up(void); +#endif + +int main(){ + int score = 0; + int highscore; + int input; + int dir; + bool collision; + int fruit_loc[2]; //index 0 is x, 1 is y + bool fruit_bool; + bool new_hs_flag; + int i; + + //TODO consider removing score2 altogether + + srand(time(NULL)); + + initscr(); + cbreak(); + keypad(stdscr, true); + noecho(); + curs_set(0); + set_escdelay(1); + + while(input != 'q'){ + clear(); + + //reset variables + collision = false; + fruit_bool = false; + score = 0; + new_hs_flag = false; + highscore = loadScore(); + + + //draw current score, and high score + updateScore(0, score); + updateScore(1, highscore); + + //the snake will be initially drawn without calling to body.h + //functions in body.h will update the snake and check for collision + //updateScreen() will actually draw the snake on each update (and update the scoreboard) + + //initialize and draw starting snake + SNAKE *player = makeSnake(START_SIZE+2, getmaxy(stdscr)/2, START_SIZE); + //TODO consider various choices for drawing the snake (the below sets reverse video and draws spaces) + attron(A_REVERSE); + mvaddch(getmaxy(stdscr)/2, START_SIZE+2, ':'); + for(i = 1; START_SIZE-i > 0; i++){ + mvaddch(getmaxy(stdscr)/2, START_SIZE+2-i, ' '); + } + attroff(A_REVERSE); + + //TODO add something like "press any key to start!" + getch(); + + //turn timeout on and set the initial direction to "right" + timeout(TIMEOUT); + dir = 1; + while(!collision){ + input = getch(); + + //update dir based on received input (check that the input is valid as well) + switch(input){ + case KEY_UP: + if(dir % 2) dir = 0; + break; + case KEY_RIGHT: + if(!(dir % 2)) dir = 1; + break; + case KEY_DOWN: + if(dir % 2) dir = 2; + break; + case KEY_LEFT: + if(!(dir % 2)) dir = 3; + } + + updateScore(0, score); + if(score > highscore){ + highscore = score; + new_hs_flag = true; + } + updateScore(1, highscore); + updateScreen(player, dir, &collision, fruit_loc, &fruit_bool, &score); + //TODO consider changing SPEED depending on if moving horizontally or vertically + refresh(); + usleep(SPEED); + } + + deleteSnake(player); + if(new_hs_flag) saveScore(highscore); + + //turn timeout off (wait for input again) + timeout(-1); + + //TODO add something like "game over" + while(input != 'q' && input != ' ' && input != 10) input = getch(); + + //DEBUG +#ifdef DEBUG + //count_up(); + getch(); +#endif + } + + endwin(); + return 0; +} + +// 0 for p1 score, 1 for highscore, 2 for p2 score +void updateScore(int which, int score){ + char *title; + int start; + + switch(which){ + case 0: //p1 score + title = "Score"; + start = 2; + break; + + case 1: //high score + title = "Highscore"; + start = getmaxx(stdscr)/2 - 5; + break; + + default: + exit(1); + } + + //draw the title and the score in the right location + mvprintw(0, start, "%s", title); + mvprintw(1, start + (which % 2 ? 5 : 3) - (!score ? 0 : (int)log10(score)), "%d", score); + + return; +} + +void updateScreen(SNAKE *sp, int dir, bool *collision, int *fruit_loc, bool *fruit, int *score){ + char eyes; + + //switch case to decide "eyes" char + switch(dir){ + case 0: + eyes = '"'; + break; + case 2: + eyes = '.'; + break; + default: + eyes = ':'; + } + + //turn off "back" + mvaddch(getSnakeHeady(sp), getSnakeHeadx(sp), ' '); + //fix previous "front" (no more eyes) + attron(A_REVERSE); + mvaddch(getSnakeTaily(sp), getSnakeTailx(sp), ' '); + //update the snake position + updateSnake(sp, dir, getmaxx(stdscr), getmaxy(stdscr), collision, fruit_loc, fruit, score); + //turn on front + mvaddch(getSnakeTaily(sp), getSnakeTailx(sp), eyes); + attroff(A_REVERSE); + + //TODO add logic to prevent fruit from spawning inside snake + //draw a new fruit, if necessary (do not draw it over scoreboard) + if(!(*fruit)){ + *fruit_loc = rand() % getmaxx(stdscr); + *(fruit_loc+1) = rand() % (getmaxy(stdscr)-2) + 2; + attron(A_BOLD); + mvaddch(*(fruit_loc+1), *fruit_loc, '@'); + attroff(A_BOLD); + *fruit = true; + } + + return; +} + +int loadScore(){ + FILE *savedata; + char *path = malloc(sizeof(char) * 256); + int hs = 0; + char *home = getenv("HOME"); + + sprintf(path, "%s/.local/share/simple-snake/save.bin", home); + savedata = fopen(path, "rb"); + + if(savedata != NULL){ + fread(&hs, sizeof(int), 1, savedata); + fclose(savedata); + } + + free(path); + return hs; +} + +void saveScore(int highscore){ + FILE *savedata; + char *path = malloc(sizeof(char) * 256); + char *home = getenv("HOME"); + + sprintf(path, "%s/.local/share/simple-snake/save.bin", home); + savedata = fopen(path, "wb"); + + //if the file does not exist, create it + if(savedata == NULL){ + if(home == NULL) return; + + sprintf(path, "%s/.local/", home); + mkdir(path, 0700); + + sprintf(path, "%s/.local/share/", home); + mkdir(path, 0755); + + sprintf(path, "%s/.local/share/simple-snake/", home); + mkdir(path, 0755); + + sprintf(path, "%s/.local/share/simple-snake/save.bin", home); + savedata = fopen(path, "wb"); + if(savedata == NULL) return; + } + + fwrite(&highscore, sizeof(int), 1, savedata); + fclose(savedata); + + free(path); + return; +} + + +//debug functions start here +#ifdef DEBUG +void count_up(){ + int score = 0; + int score2 = 0; + int highscore = 0; + + while(1){ + score++; + score2++; + highscore++; + updateScore(0, score); + updateScore(1, highscore); + updateScore(2, score2); + refresh(); + usleep(50000); + } + + return; +} +#endif |