def prompt_user(player, game_master, available_commands, end_condition_callback=lambda _,__: False): prompt_user.available_commands = available_commands user_input = _INVALID_INITIAL_INPUT while not user_input_finished(user_input) and not \ end_condition_callback(player, game_master): command = None user_input = None args = None try: # verifies that it is a valid command in the list user_input, args = risk_input('Please type a command') command = available_commands[user_input] command(player, game_master, *args) except KeyError: risk.logger.error('%s is not a valid command in the ' \ 'reinforcement stage' % user_input) risk.logger.debug(available_commands.keys()) print 'invalid command' except (RiskGameError, ValueError, TypeError, IndexError) as e: risk.logger.error(str(e)) if not command: help_info(player, game_master) elif command.__doc__: print "usage: %s" % command.__doc__ else: print command print user_input print args risk.logger.warn("%s syntax error and no usage. "\ "User input: '%s', args: '%s'" % (command, user_input, args))
def prompt_user(player, game_master): user_input = _INVALID_INITIAL_INPUT while not user_input_finished(user_input): try: # verifies that it is a valid command in the list user_input = risk_input('Please type a command') user_commands[user_input](player, game_master) except KeyError: print 'invalid command'
def prompt_user(player, game_master, available_commands, end_condition_callback=lambda _,__: False): prompt_user.available_commands = available_commands user_input = _INVALID_INITIAL_INPUT while not user_input_finished(user_input) and not \ end_condition_callback(player, game_master): command = None user_input = None args = None try: # verifies that it is a valid command in the list user_input, args = risk_input('Please type a command') command = available_commands[user_input] execute_command(command, player, game_master, *args) except KeyError: risk.logger.error('%s is not a valid command in the ' \ 'reinforcement stage' % user_input) risk.logger.debug(available_commands.keys()) print 'invalid command'
def prompt_user(player, game_master): user_input = _INVALID_INITIAL_INPUT while not user_input_finished(user_input): command = None user_input = None args = None try: # verifies that it is a valid command in the list user_input, args = risk_input('Please type a command') command = user_commands[user_input] command(player, game_master, *args) except KeyError: print 'invalid command' except Exception as e: risk.logger.error(str(e)) if command.__doc__: print "usage: %s" % command.__doc__ else: print command print user_input print args risk.logger.warn("%s syntax error and no usage. "\ "User input: '%s', args: '%s'" % (command, user_input, args))
def pick_territory(self, choices): risk_input("Choose a territory...") print choices