Exemple #1
0
    def process_move(self, dung_map):
        """
        :param dung_map: map of the game
        :type dung_map: DungeonMap
        """

        position = self.position
        size = len(dung_map.dun_map)
        command = self.command
        game_map = dung_map.dun_map

        if command not in COMMANDS:
            raise dungeon_exception.CommandError('Invalid command was entered!')

        dungeon_logger.logger.debug(f"Move with command: {command}")
    
        try:
            game_map[position[0]][position[1]] = '0'
        except TypeError as error:
            dungeon_logger.logger.info(f'TypeError occured: {error}')
        move_ret_val = dungeon_logic.make_move_if_possible(position, size, command)
        
        if move_ret_val == False:

            dungeon_logger.logger.info('Move is not possible')
            game_map[position[0]][position[1]] = 'y'

            return
        
        cage_state = dungeon_logic.check_pos(game_map, position)
        cages = dungeon_logic.check_closest_pos(game_map, position, size)
        for cage in cages:
            dungeon_logger.logger.info(WARNINGS[cage])

        try:
            game_map[position[0]][position[1]] = 'y'
        except IndexError as error:
            dungeon_logger.logger.info(f'Player on wrong position/n IndexError: {error}')

        if cage_state == 'bomb':
            
            try:
                self.applay_damage(1)
            except dungeon_exception.DamageError as error:
                dungeon_logger.logger.info(f'DamageError raised: {error}')
            dungeon_logger.logger.info('You picked the bomb')
        
        elif cage_state == 'treasue':
            self.change_score(1)
            dungeon_logger.logger.info('You picked the treasure')

        elif cage_state is not 'empty':
            raise dungeon_exception.MapCageError(game_map, position, cage_state)
Exemple #2
0
    def process_move(self, player):
        """
        :param player: player that must make a move
        :type player: Player
        """

        position = player.position
        size = len(self.dun_map[0])
        command = player.command

        dungeon_logger.logger.debug(f"Move with command: {command}")
    
        self.dun_map[position[0]][position[1]] = '0'
        move_ret_val = dungeon_logic.make_move_if_possible(position, size, command)
        
        if move_ret_val == False:

            dungeon_logger.logger.info('Move is not possible')
            self.dun_map[position[0]][position[1]] = 'y'

            return
        
        cage_state = dungeon_logic.check_pos(self.dun_map, position)
        cages = dungeon_logic.check_closest_pos(self.dun_map, position, size)
        for cage in cages:
            dungeon_logger.logger.info(WARNINGS[cage])

        self.dun_map[position[0]][position[1]] = 'y'

        if cage_state == 'bomb':
            
            player.applay_damage(1)
            dungeon_logger.logger.info('You picked the bomb')
        
        elif cage_state == 'treasue':
            player.change_score(1)
            dungeon_logger.logger.info('You picked the treasure')