Esempio n. 1
0
    def run(self):
        """ Function realize main logic of game """
        while self.player.is_alive() and not self.player.is_winner():

            self.warn_situation()

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

            if not self.is_direction_blocked(choice):
                self.player.move_to(choice)

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

                    if is_winning:
                        self.player.increase_treasure_amount()
                    else:
                        self.player.get_trapped()

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

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

        self.game_finished_event.set()
Esempio n. 2
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.')
Esempio n. 3
0
    dungeon_game_logic.warn_situation_in_cell(game_map, x, y)
    logger.debug('The situation was warned successfully.')

    choice = dungeon_game_logic.recognize_input()
    if choice == dungeon_game_logic.SAVE_COMMAND_INDEX:
        dungeon_game_logic.save_game(game_map, x, y)
        while choice == dungeon_game_logic.SAVE_COMMAND_INDEX:
            choice = dungeon_game_logic.recognize_input()

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

    if not dungeon_game_logic.is_direction_blocked(game_map, choice, x, y):
        x, y = dungeon_game_logic.get_new_coordinates(choice, x, y)
        logger.debug('The player moved to ({0}, {1})'.format(x, y))

        if dungeon_game_logic.is_game_over(game_map, x, y):
            is_winning = dungeon_game_logic.check_game_win(game_map[x][y])
            dungeon_game_logic.show_game_result(is_winning)
            is_game_continuos = False
            logger.debug('The game over')

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

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

level_builder.show_level_map(game_map)

logger.debug('The game is finished successfully.')