From 5184bd9121f258d0b171d153f2cb4ec72bf595d2 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:53:27 -0500 Subject: [PATCH] Add some more handling for commands --- Adventure Game/adventure_game/Handler.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 78ac1a7..860bb65 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -22,10 +22,22 @@ class Handler(npyscreen.ButtonPress): except IndexError: self.parent.parentApp.log.warn('Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) command = '' - arguments = parsed_command # Whatever is left in the list, are arguments. + arguments = parsed_command # Whatever is left in the list, are arguments. + # Handle an empty command + if len(command) <= 2: + self.parent.update_log('Command was too short, try something like "MOVE", "PICK UP" or "USE".') + + else: + # Concatenate everything back together (just to show the user the program understood them correctly + self.parent.update_log(command + ' ' + ' '.join(str(s) for s in arguments)) + + # Log the command that we parsed self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) - self.parent.update_log('command: ' + command) - self.parent.update_log('args: {0}'.format(arguments)) + + # Make sure to re-draw the art box when we're all done (in case we updated it in logic above) self.parent.artContent.display() + + # Switch back to the game menu. + #TODO: possibly deprecate this statement? self.parent.parentApp.switchForm('GAME')