diff --git a/Makefile b/Makefile index b9b5c65..f29aa40 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,33 @@ -# Universal makefile for single C++ program -# -# Use gcc flag -MMD (user) or -MD (user/system) to generate dependencies among source files. -# Use make default rules for commonly used file-name suffixes and make variables names. -# -# % make [ a.out ] - -########## Variables ########## - -CXX = g++ # compiler -CXXFLAGS = -std=c++20 -g -Wall -MMD -lncurses -O0 # compiler flags -MAKEFILE_NAME = ${firstword ${MAKEFILE_LIST}} # makefile name - -SOURCES = $(wildcard src/*.cc) # source files (*.cc) -OBJECTS = ${SOURCES:.cc=.o} # object files forming executable -DEPENDS = ${OBJECTS:.o=.d} # substitute ".o" with ".d" -EXEC = bin/cc3k # executable name - -########## Targets ########## - -.PHONY : clean # not file names - -${EXEC} : ${OBJECTS} # link step - ${CXX} ${CXXFLAGS} $^ -o $@ # additional object files before $^ - -${OBJECTS} : ${MAKEFILE_NAME} # OPTIONAL : changes to this file => recompile - -# make implicitly generates rules to compile C++ files that generate .o files - --include ${DEPENDS} # include *.d files containing program dependences - -clean : # remove files that can be regenerated - rm -f ${DEPENDS} ${OBJECTS} ${EXEC} +# Universal makefile for single C++ program +# +# Use gcc flag -MMD (user) or -MD (user/system) to generate dependencies among source files. +# Use make default rules for commonly used file-name suffixes and make variables names. +# +# % make [ a.out ] + +########## Variables ########## + +CXX = g++ # compiler +CXXFLAGS = -std=c++20 -g -Wall -MMD -lncurses -O0 # compiler flags +MAKEFILE_NAME = ${firstword ${MAKEFILE_LIST}} # makefile name + +SOURCES = $(wildcard src/*.cc) # source files (*.cc) +OBJECTS = ${SOURCES:.cc=.o} # object files forming executable +DEPENDS = ${OBJECTS:.o=.d} # substitute ".o" with ".d" +EXEC = bin/cc3k # executable name + +########## Targets ########## + +.PHONY : clean # not file names + +${EXEC} : ${OBJECTS} # link step + ${CXX} ${CXXFLAGS} $^ -o $@ # additional object files before $^ + +${OBJECTS} : ${MAKEFILE_NAME} # OPTIONAL : changes to this file => recompile + +# make implicitly generates rules to compile C++ files that generate .o files + +-include ${DEPENDS} # include *.d files containing program dependences + +clean : # remove files that can be regenerated + rm -f ${DEPENDS} ${OBJECTS} ${EXEC} diff --git a/src/console_input.cc b/src/console_input.cc index 69cafc6..e7d2a2c 100644 --- a/src/console_input.cc +++ b/src/console_input.cc @@ -10,21 +10,26 @@ game_command console_input::get_command() { in >> cmd; game_command tmp; + if (in.eof()) + return game_command_terminate; + if (cmd == "q") return game_command_terminate; else if (cmd == "f") return the_world; else if (cmd == "r") return game_restart; - else if (cmd == "u") + else if (cmd == "u" || cmd == "a") { + in >> cmd; + + if (in.eof()) + return game_command_panic; + return (game_command)((tmp = get_direction(cmd)) == game_command_panic - ? tmp : tmp - move_north + apply_north); - else if (cmd == "a") - return (game_command)((tmp = get_direction(cmd)) == - game_command_panic - ? tmp : tmp - move_north + attack_north); - else // is just moving + ? tmp : tmp - move_north + + (cmd == "u" ? apply_north : attack_north)); + } else // is just moving return get_direction(cmd); return game_command_pass; diff --git a/src/file_input.cc b/src/file_input.cc index 745df64..54600e0 100644 --- a/src/file_input.cc +++ b/src/file_input.cc @@ -10,21 +10,26 @@ game_command file_input::get_command() { in >> cmd; game_command tmp; + if (in.eof()) + return game_command_terminate; + if (cmd == "q") return game_command_terminate; else if (cmd == "f") return the_world; else if (cmd == "r") return game_restart; - else if (cmd == "u") + else if (cmd == "u" || cmd == "a") { + in >> cmd; + + if (in.eof()) + return game_command_panic; + return (game_command)((tmp = get_direction(cmd)) == game_command_panic - ? tmp : tmp - move_north + apply_north); - else if (cmd == "a") - return (game_command)((tmp = get_direction(cmd)) == - game_command_panic - ? tmp : tmp - move_north + attack_north); - else // is just moving + ? tmp : tmp - move_north + + (cmd == "u" ? apply_north : attack_north)); + } else // is just moving return get_direction(cmd); return game_command_pass; diff --git a/tools/compile b/tools/compile old mode 100755 new mode 100644 index 5a24514..92ad5b9 --- a/tools/compile +++ b/tools/compile @@ -1,25 +1,25 @@ -#!/bin/bash -# Use this script to compile your .cc files in dependency order - -# Arguments: -# $1 = name of file containing list of .cc files -# $2 = name of the output file - -cxx="g++-11" -cxxflags="-std=c++20 -fmodules-ts -Wall -g" - -if [ $# -lt 1 ]; then - echo "Usage: $0 list-filename [output-name]" 1>&2 - exit 1 -fi - -if [ $# -eq 2 ]; then - name="-o $2" -fi - -for x in $(cat $1); do - $cxx $cxxflags -c $x -done - -$cxx *.o $name - +#!/bin/bash +# Use this script to compile your .cc files in dependency order + +# Arguments: +# $1 = name of file containing list of .cc files +# $2 = name of the output file + +cxx="g++-11" +cxxflags="-std=c++20 -fmodules-ts -Wall -g" + +if [ $# -lt 1 ]; then + echo "Usage: $0 list-filename [output-name]" 1>&2 + exit 1 +fi + +if [ $# -eq 2 ]; then + name="-o $2" +fi + +for x in $(cat $1); do + $cxx $cxxflags -c $x +done + +$cxx *.o $name + diff --git a/tools/produceOutputs b/tools/produceOutputs old mode 100755 new mode 100644 diff --git a/tools/runSuite b/tools/runSuite old mode 100755 new mode 100644