Advertisement
Nizarus

combat

Oct 7th, 2022
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.49 KB | Gaming | 0 0
  1. import random
  2. import numpy as np
  3.  
  4. class Character:
  5.         def __init__(self, name="character", gender="male"):
  6.             self.name=name
  7.             self.gender=gender
  8.             self.age=np.random.randint(15,55)
  9.             self.exp=0
  10.         def attributes(self, health, damage, resistance):
  11.             if self.age<20:
  12.                 self.health=health-5
  13.             elif self.age>40:
  14.                 self.health=health-5
  15.             else:
  16.                 self.health=health
  17.             self.skill="cleave"
  18.             self.damage=damage
  19.             self.resistance=resistance
  20.         def level_up(self, kills=0):
  21.             count=0
  22.             for kill in range(kills):
  23.                 count+=1
  24.             self.exp=count
  25.             if self.exp==10:
  26.                 self.damage+=10
  27.  
  28.  
  29. class Enemy (Character):
  30.     pass
  31.  
  32. class Ally(Character):
  33.     pass
  34.  
  35. def main():
  36.     #define the hero
  37.     name=input("Name: ")
  38.     gender=gn()
  39.     hero=Character(name,gender)
  40.     health, damage, resistance=attr()
  41.     hero.attributes(health, damage, resistance)
  42.     for r in range(np.random.randint(10)):
  43.         print(f"round:{r}")
  44.         casualties=combatphases(hero, r)
  45.         for casualty in casualties:
  46.             del casualty
  47. def combatpreparation(hero):
  48.     enemies=[]
  49.     allies=[]
  50.     count=0
  51.     number_of_enemies=np.random.randint(5,10)
  52.     number_of_allies=np.random.randint(1,5)
  53.     for en in range(number_of_enemies):
  54.         count+=1
  55.         name=f"enemy {count}"
  56.         gender=random.choice(["male", "female"])
  57.         enemy=Enemy(name, gender)
  58.         enemy.health=np.random.randint(5, 10)
  59.         enemy.damage=np.random.randint(2,8)
  60.         enemy.resistance=enemy.health/2
  61.         enemies.append(enemy)
  62.     for al in range(number_of_allies):
  63.         count+=1
  64.         name=f"ally {count}"
  65.         gender=random.choice(["male", "female"])
  66.         ally=Ally(name, gender)
  67.         ally.health=np.random.randint(10,15)
  68.         ally.damage=np.random.randint(1,5)
  69.         ally.resistance=ally.health/3
  70.         allies.append(ally)
  71.     return allies, enemies
  72. def combatphases(hero, r):
  73.     combat1=[]
  74.     combat2=[]
  75.     enemies=[]
  76.     allies=[]
  77.     attacks=[]
  78.  
  79.     for i in range(1,r):
  80.             allies, enemies=combatpreparation(hero)
  81.             allies.append(hero)
  82.             for ally in allies:
  83.                 combat1.append({ally.name: (ally.health, ally.damage)})
  84.             for enemy in enemies:
  85.                 combat2.append({enemy.name: (enemy.health, enemy.damage)})
  86.  
  87.     for j in combat1:
  88.         ally=random.choice(allies)
  89.         enemy=random.choice(enemies)
  90.         count=0
  91.         if ally==hero:
  92.             if count<2:
  93.                 decide=input("Press Y to use cleave: ")
  94.                 count+=1
  95.                 if decide=="Y":
  96.                     print(f"{hero.name} uses cleave")
  97.                     hero.health+=1
  98.                     attacking=attack(ally, enemy, True)
  99.                     attacking=attack(ally,enemy)
  100.                 else:
  101.                     pass
  102.             else:
  103.                 attacking=attack(ally,enemy)
  104.                 attacks.append(attacking)
  105.                 hero.health+=1
  106.     for k in combat2:
  107.         hero.health+=1
  108.         ally=random.choice(allies)
  109.         enemy=random.choice(enemies)
  110.         attacked=attack(enemy, ally)
  111.         attacks.append(attacked)
  112.     return attacks
  113. def attack(attacker, attacked, cleave=False):
  114.     res=""
  115.     luck1=random.choice([1,2,3,4])
  116.     luck2=random.choice([1,2,3])
  117.     damage=attacker.damage*luck2
  118.     if cleave==False:
  119.         damage=damage/luck1
  120.     else:
  121.         damage=damage+2
  122.     health=attacked.health
  123.     attacked.health=health-damage
  124.     if attacked.health>0:
  125.         print(f"{attacker.name} attacks {attacked.name}:{health} with a normal attack causing {damage} damage")
  126.         return Character("none","None")
  127.     else:
  128.         print(f"{attacker.name} deals a mortal blow to {attacked.name}. {attacked.name} dies!")
  129.         res=attacked
  130.         return res
  131. def attr():
  132.     health=hlth()
  133.     damage=10-(health/10)
  134.     resistance=health/2
  135.     return health, damage, resistance
  136. def hlth():
  137.     try:
  138.         health=int(input("health min 10 max20: "))
  139.         if 20<health or health<10:
  140.             hlth()
  141.         else:
  142.             return health
  143.     except:
  144.         hlth()
  145. def gn():
  146.     gender=input("Gender: ")
  147.     if gender!="male" and gender!="female":
  148.         gn()
  149.     else:
  150.         return gender
  151.  
  152. if __name__=="__main__":
  153.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement