Загрузка данных


import random
import time


class Trainer:

    def __init__(self, name, gold = 50):
        self.name = name
        self.gold = gold
        creatures = []

    def can_afford(self, price):
        if price > self.gold:
            return False
        else: return True

    def pay(self, price):
        self.gold -= price


class Shop:

    def __init__(self):
        self.items = {"name": "Восполох", "hp": 75, "price": 50}

    def show(self):
        creature_name = self.items["name"]
        creature_price = self.items["price"]
        print(creature_name, creature_price)

    def sell(self, trainer: Trainer, items):
        if trainer.can_afford(items["price"]) == True:
            trainer.pay(items["price"])
            print(f"Вы смогли купить {items['name']} за {items['price']} и у вас осталось {trainer.gold}")
        else: print(f"Вы не смогли купить {items['name']} за {items['price']}")


class Battle:

    def __init__(self, trainer: Trainer, shop: Shop):
        self.hero_hp = shop.items["hp"]
        self.hero_name = shop.items["name"]
        self.enemy_name = "Антон Буйный"
        self.enemy_hp = 45

    def fight(self):
        print(f"Начало боя с {self.enemy_name}")
        while True:
            time.sleep(0.5)
            random_hero_num = random.randint(1, 50)
            random_hero_num2 = random.randint(1, 10)
            random_enemy_num = random.randint(1, 35)
            print("\nВыбери 1 или 2")
            print("1. Атаковать")
            print("2. Пропустить ход (есть шанс уклонится)")
            hod = int(input("Выбери: "))
            if not (1 < hod > 2):
                restart = False
            if hod == 1:
                self.enemy_hp -= random_hero_num
                self.hero_hp -= random_enemy_num
                if self.enemy_hp <= 0:
                    self.enemy_hp = 0
                if self.hero_hp <= 0:
                    self.hero_hp = 0
                print(f"\nВы нанесли {random_hero_num} урона и у врага осталось {self.enemy_hp}")
                if self.enemy_hp <= 0:
                    return print("Победа")
                print(f"Вам нанесли {random_enemy_num} урона и у вас осталовь {self.hero_hp}")
                if self.hero_hp == 0:
                    return print("Поражение")
            if hod == 2:
                if random_hero_num2 > 4:
                    print("\nВы уклонились")
                if random_hero_num2 <= 4:
                    self.hero_hp -= random_enemy_num
                    print(f"\nУклониться не удалось и вам нанесли {random_enemy_num} урона и у вас осталось {self.hero_hp}")


class Game(Trainer, Shop, Battle):

    def start_game(self):
        print(f"Саламалексус {self.name}")
        time.sleep(0.2)
        restart = True
        while restart:
            restart = True
            print("\n1. Пойти в магазин")
            print("2. Бой")

shop = Shop()
trainer = Trainer("Anton")
battle = Battle(trainer, shop)
game = Game("Антон")

battle.fight()