From 9495f11c16f39e8859963d53445e726a549fe4b6 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Fri, 5 Jul 2024 21:28:45 -0400 Subject: [PATCH] fixed issue panic in console/file input --- src/console_input.cc | 8 ++++++-- src/console_output.cc | 8 +++++++- src/file_input.cc | 8 ++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/console_input.cc b/src/console_input.cc index 531176f..566fab3 100644 --- a/src/console_input.cc +++ b/src/console_input.cc @@ -31,8 +31,12 @@ game_command console_input::get_command() { game_command_panic ? tmp : tmp - move_north + (use ? apply_north : attack_north)); - } else // is just moving - return get_direction(cmd); + } else { + auto tmp = get_direction(cmd); + + if (tmp != game_command_panic) + return tmp; + } return game_command_pass; } diff --git a/src/console_output.cc b/src/console_output.cc index c2d6846..cf00af1 100644 --- a/src/console_output.cc +++ b/src/console_output.cc @@ -1,6 +1,7 @@ #include "console_output.h" #include +#include #include @@ -73,10 +74,15 @@ void console_output::render() { if (idx % DISPLAY_WIDTH == 0 && idx) out << std::endl; - out << get_code(contents[idx]) + (char)contents[idx]; + out << get_code(contents[idx]) + + (char)(contents[idx] ? contents[idx] : ' '); } } +void console_output::clear() { + +} + void console_output::print_char(const position &pos, const char ch, const int attr) { if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) diff --git a/src/file_input.cc b/src/file_input.cc index e2ed7d7..ba9a762 100644 --- a/src/file_input.cc +++ b/src/file_input.cc @@ -31,8 +31,12 @@ game_command file_input::get_command() { game_command_panic ? tmp : tmp - move_north + (use ? apply_north : attack_north)); - } else // is just moving - return get_direction(cmd); + } else { + auto tmp = get_direction(cmd); + + if (tmp != game_command_panic) + return tmp; + } return game_command_pass; }