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