def enter(self, player, possible_actions=ER_ACTIONS, action_message=ER_ACTION_MESSAGE, passed_actions=ACTION_DIRECTIONS): # Gets the possible directions based on input when entering the room. self.directions = [ self.DIRECTIONS[i] for i, x in enumerate(self.doors) if x ] action = None # Get user action and keep going until directional action is found while action not in passed_actions: # Get action action = input(PROMPT) print('') # Interpret action and translate to standard action action = act.interpret_act(action) if action != None: # Check if action is allowed in this room if len(action.split() ) == 1 and action in possible_actions.keys(): action_allowed = True elif len(action.split()) == 2 and action.split( )[0] in possible_actions.keys() and action.split( )[1] in possible_actions[action.split()[0]]: action_allowed = True elif len(action.split()) == 3 and action.split( )[0] in possible_actions.keys() and ( action.split()[1] + ' ' + action.split()[2] ) in possible_actions[action.split()[0]]: action_allowed = True else: action_allowed = False if action_allowed: # If action is understood and not directional if action not in ACTION_DIRECTIONS: # Perform standard action player, action, self = act.perform_action( self, action, player, possible_actions) elif action == 'go north': next_pos = (player.position[0], player.position[1] - 1) elif action == 'go south': next_pos = (player.position[0], player.position[1] + 1) elif action == 'go west': next_pos = (player.position[0] - 1, player.position[1]) elif action == 'go east': next_pos = (player.position[0] + 1, player.position[1]) elif action == 'go back': next_pos = player.prev_pos if action in ACTION_DIRECTIONS: if player.map_data[next_pos[1]][next_pos[0]] == '-': print( "Can't go in that direction. There is a wall in the way." ) action = None else: print(action_message) action = None # Else else: # Continue looping for new input pass # if action in ACTION_DIRECTIONS: # Update player position based on (directional) action player.update_pos(next_pos[0], next_pos[1]) # Return player. return player
def do_action(self, dir): action = self.command_action_dict[dir] action.perform_action()
def perform_action(self): action.perform_action(self.config, self.direction, 'Hand')