Advertisement
Chl_Snt

№20. RPG: Подземелья

Jul 13th, 2023
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.20 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4.  
  5. class Player:
  6.     def __init__(self, name, hp, damage):
  7.         self.name = name
  8.         self.hp = hp
  9.         self.damage = damage
  10.  
  11.     def attack(self, victim):
  12.         victim.hp -= self.damage
  13.         print(f"Ты нанёс врагу {self.damage} урона. Теперь у него {victim.hp} здоровья.")
  14.         if victim.hp <= 0:
  15.             print(f"{victim.name} повержен!")
  16.             return False
  17.         else:
  18.             return True
  19.  
  20.  
  21. class Enemy:
  22.     races = {
  23.         "Слизняк": (10, 10),
  24.         "Волк": (25, 20),
  25.         "Орк": (50, 45),
  26.         "Группа гоблинов": (120, 25),
  27.         "Оборотень": (150, 50)
  28.     }
  29.  
  30.     def __init__(self):
  31.         self.name = random.choice(list(self.races.keys()))
  32.         self.hp = self.races[self.name][0]
  33.         self.damage = self.races[self.name][1]
  34.  
  35.     def attack(self, victim):
  36.         victim.hp -= self.damage
  37.         print(f"{self.name} нанёс тебе {self.damage} урона. Теперь у тебя {victim.hp} здоровья.")
  38.         if victim.hp <= 0:
  39.             exit(print("ПОТРАЧЕНО!"))
  40.         else:
  41.             return True
  42.  
  43.  
  44. def create_hero(name, race, prof):
  45.     hp = 100
  46.     dmg = 25
  47.     hp *= races[race][0]
  48.     hp *= profs[prof][0]
  49.     dmg *= races[race][1]
  50.     dmg *= profs[prof][1]
  51.     hero = Player(name, hp, dmg)
  52.     return hero
  53.  
  54.  
  55. def start():
  56.     enemy = Enemy()
  57.     print(f"Тебе встретился {enemy.name}. ❤️: {enemy.hp}, ⚔️: {enemy.damage}")
  58.     print("Нападать?")
  59.     answer = input("Да/Нет: ").lower()
  60.     if answer == "да":
  61.         fight(enemy)
  62.     else:
  63.         luck = random.randint(1, 100)
  64.         if luck in range(40):
  65.             print("Ты смог незаметно ускользнуть и пойти дальше!")
  66.             time.sleep(2)
  67.             start()
  68.         else:
  69.             print("Ты НЕ смог незаметно ускользнуть!")
  70.             time.sleep(2)
  71.             enemy.attack(hero)
  72.             fight(enemy)
  73.  
  74.  
  75. def fight(victim):
  76.     result = hero.attack(victim)
  77.     time.sleep(1)
  78.     if result:
  79.         victim.attack(hero)
  80.         time.sleep(1)
  81.         fight(victim)
  82.     else:
  83.         start()
  84.  
  85.  
  86. name = input("Введи своё имя: ")
  87.  
  88. races = {
  89.     "эльф": (1.5, 1),
  90.     "гном": (0.8, 1.2),
  91.     "человек": (1, 1)
  92. }
  93.  
  94. profs = {
  95.     "лучник": (0.9, 2),
  96.     "щитоносец": (2, 0.6),
  97.     "рыцарь": (1.2, 1.2)
  98. }
  99.  
  100. race = ""
  101. prof = ""
  102. while race not in tuple(races.keys()):
  103.     print(f"Выбери расу: {tuple(races.keys())}")
  104.     race = input("-> ").lower()
  105.  
  106. while prof not in tuple(profs.keys()):
  107.     print(f"Выбери профессию: {tuple(profs.keys())}")
  108.     prof = input("-> ").lower()
  109.  
  110. hero = create_hero(name, race, prof)
  111. print(f"Здравствуй, герой с именем {hero.name}!\n"
  112.       f"Твоё здоровье равно {hero.hp} ХП.\n"
  113.       f"Твой урон равен {hero.damage} единицам.\n"
  114.       f"Желаю удачи в приключениях, странник! ^_+")
  115. time.sleep(1)
  116. start()
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement