Esempio n. 1
0
    def __movement(self, new_hero_pos):
        if self.__map[new_hero_pos[0]][new_hero_pos[1]] in ['#', 'T', 'E']:
            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == '#':
                return False

            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'T':
                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
                self.__hero_pos = new_hero_pos

                treasure = self.spawn_treasure()
                if isinstance(treasure, ManaPotion):
                    print("Mana pot found")
                    mana = treasure.get_mana()
                    self.__hero.take_mana(mana)
                    print("Hero healed with {} mana".format(mana))
                    print("Hero's mana is: {}".format(self.__hero.get_mana()))

                if isinstance(treasure, HealthPotion):
                    print("Healing pot found!")
                    health = treasure.get_health()
                    self.__hero.take_healing(health)
                    print("Hero healed with {} health".format(health))
                    print(
                        "Hero;s health is: {}".format(
                            self.__hero.get_health()))

                if isinstance(treasure, Weapon):
                    print("Weapon found!")
                    self.__hero.equip(treasure)

                if isinstance(treasure, Spell):
                    print("Spell found!")
                    self.__hero.learn(treasure)

                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
                return True

            if self.__map[new_hero_pos[0]][new_hero_pos[1]] == 'E':
                print("Enemy found")
                self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
                self.__hero_pos = new_hero_pos

                # enemy spawner
                enemy = Enemy(health=random.randrange(50, 150),
                              mana=random.randrange(20, 100),
                              damage=random.randrange(20, 80))

                # initiate fight
                fight = Fight(self.__hero, enemy)
                result = fight.static_fight()
                if result:
                    print("Hero wins")
                    self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
                    return True
                else:
                    print("Hero is dead! Respawning...")
                    self.spawn(self.__hero)
                    return False
            return True
        else:
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = '.'
            self.__hero_pos = new_hero_pos
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
            return True
Esempio n. 2
0
    def hero_atack(self):
        enemy = Enemy(health=random.randrange(50, 150),
                      mana=random.randrange(20, 100),
                      damage=random.randrange(20, 80))

        # finding the enemy
        distance = 0
        curr_vec = 1
        row = self.__hero_pos[0]
        col = self.__hero_pos[1]
        choices = []
        range_to_enemy = 0
        atack_range = self.__hero.get_cast_range()

        if atack_range:
            while row - curr_vec >= 0 and curr_vec <= atack_range:
                if self.__map[row - curr_vec][col] == '#':
                    break
                choices.append((row - curr_vec, col))
                curr_vec -= 1

            curr_vec = 1
            while col + curr_vec < self.__cols and curr_vec <= atack_range:
                if self.__map[row][col + curr_vec] == '#':
                    break
                choices.append((row, col + curr_vec))
                curr_vec += 1

            curr_vec = 1
            while row + curr_vec < self.__rows and curr_vec <= atack_range:
                if self.__map[row + curr_vec][col] == '#':
                    break

                choices.append((row + curr_vec, col))
                curr_vec += 1

            curr_vec = 1
            while col - \
                    curr_vec >= 0 and curr_vec <= atack_range and self.__map[row][col - curr_vec] != '#':
                if self.__map[row][col - curr_vec] == '#':
                    break

                choices.append(row, col + curr_vec)
                curr_vec -= 1
        fight = Fight(self.__hero, enemy)
        fight_pos = 0
        for elem in choices:
            if self.__map[elem[0]][elem[1]] == 'E':
                fight_pos = elem

        if fight_pos != 0:
            range_to_enemy = max(row - fight_pos[0], col - fight_pos[1])

        for i in range(range_to_enemy):
            fight.moving_fight()

        result = fight.static_fight()
        if result:
            print("Hero wins")
            self.__map[self.__hero_pos[0]][self.__hero_pos[1]] = 'H'
            return True
        else:
            print("Hero is dead! Respawning...")
            self.spawn(self.__hero)
            return True