def update(self, player, game_finished_event):
        """ Function present main enemy update loop 
            Args:
                player(Player): object presenting player
                game_finished_event(threading.Event): event which need to set if player dead or won
        """

        while player.is_alive() and not player.is_winner():
            sleep(self.moving_interval)

            self.random_move()
            if (player.get_coordinates()) == (self.get_coordinates()):
                self.damage(player)
                if not player.is_alive():
                    game_finished_event.set()
                else:
                    self.respawn()
            else:

                x, y = player.get_coordinates()

                for _, index in enumerate(directions.values()):

                    temp_x, temp_y = Utilities.get_new_coordinates(index, x, y)

                    if (temp_x, temp_y) == (self.x, self.y):
                        logger.info('The enemy near. Run away.')
def warn_situation_in_cell(level_map, x, y):
    """ Function warns the player if there's a trap or a treasure
        within one square from him.

        Args:
            level_map(list[list]): matrix presenting play map
            x(int): coordinate by columns of player position
            y(int): coordinate by rows of player position

        Returns:
            (none)

    """

    for i, index in enumerate(directions.values()):

        if is_direction_blocked(level_map, index, x, y):
            continue

        temp_x, temp_y = get_new_coordinates(index, x, y)

        if level_map[temp_x][temp_y] == level_builder.TRAP:
            logger.info('Near a trap. Be careful.')
        elif level_map[temp_x][temp_y] == level_builder.TREASURE:
            logger.info('Near a treasure. Good luck.')
def check_start_new_game():
    """ Function checks start new game or load existing saving.
        If file does not exist, start new game

        Args:
            (none)

        Returns:
            (bool): return true if chosen start new game option,
                    otherwise - return False

    """

    logger.info(
        '\nPress "load" for loading game.\nAnything to start new game.\n')

    choice = input('Enter your choice: ')

    is_start_new_game = choice != 'load'

    if not is_start_new_game and not game_saver.check_loading_file():
        is_start_new_game = True
        logger.info('Loading does not exist. Starting new game...')

    return is_start_new_game
 def damage(self, player):
     """ Function damage player by increasing of its hp by 1 point 
         Args:
             player(Player): object presenting player
         Return: 
             (none)
     """
     player.hp -= 1
     logger.info('Player has damaged. Now {} hp'.format(player.hp))
예제 #5
0
    def show_game_result(self, is_winning):
        """ Function shows result of game

            Args:
                is_winning(bool): true if winning, otherwise - if losing

            Returns:
                (none)
        """

        result_string = 'You lose!'

        if is_winning:
            result_string = 'You won!'

        logger.info(result_string)
예제 #6
0
    def run(self):
        """ Function realize main logic of game """

        while self.player.is_alive() and not self.player.is_winner():

            logger.debug('The turn was started.')

            self.warn_situation()
            logger.debug('The situation was warned successfully.')

            choice = self.recognize_input()
            if choice == constants.SAVE_COMMAND_INDEX:
                self.save_game()
                while choice == constants.SAVE_COMMAND_INDEX:
                    choice = self.recognize_input()

            logger.debug('The direction index is {}.'.format(choice))

            if not self.is_direction_blocked(choice):
                self.player.move_to(choice)
                logger.debug('The player moved to ({0}, {1})'.format(
                    *self.player.get_coordinates()))

                if self.is_game_object_picked_up():
                    is_winning = self.check_game_win()

                    if is_winning:
                        self.player.increase_treasure_amount()
                        logger.info('The treasure picked up.')
                    else:
                        self.player.get_trapped()
                        logger.info('The player got trapped')

                    self.level_map.clear_cell(*self.player.get_coordinates())

            else:
                logger.warning("You can't move there")

            logger.debug('The turn was finished successfully.')

        self.show_game_result(self.player.is_winner())
        x, y = self.player.get_coordinates()
        self.level_map.level_matrix[x][y] = LevelMap.PLAYER
        self.level_map.show()

        logger.debug('The game is finished successfully.')
예제 #7
0
    def warn_situation(self):
        """ Function warns the player if there's a trap or a treasure
            within one square from him.  """

        level_matrix = self.level_map.level_matrix
        x, y = self.player.get_coordinates()

        for _, index in enumerate(constants.directions.values()):

            if self.is_direction_blocked(index):
                continue

            temp_x, temp_y = Utilities.get_new_coordinates(index, x, y)

            if level_matrix[temp_x][temp_y] == LevelMap.TRAP:
                logger.info('Near a trap. Be careful.')
            elif level_matrix[temp_x][temp_y] == LevelMap.TREASURE:
                logger.info('Near a treasure. Good luck.')
 def wrapper(*args, **kwargs):
     result = func(*args, **kwargs)
     logger.info(self.message)
     return result