Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import numpy as np
- class Character:
- def __init__(self, name="character", gender="male"):
- self.name=name
- self.gender=gender
- self.age=np.random.randint(15,55)
- @property
- def attributes(self, health, damage, resistance):
- if self.age<20:
- self.health=health-5
- elif self.age>40:
- self.health=health-5
- else:
- self.health=health
- self.skill="cleave"
- self.damage=damage
- self.resistance=resistance
- class Enemy (Character):
- pass
- class Ally(Character):
- pass
- def main():
- #define the hero
- name=input("Name: ")
- gender=gn()
- hero=Character(name,gender)
- health, damage, resistance=attr()
- hero.attributes(health, damage, resistance)
- for r in range(np.random.randint(10)):
- print(Character)
- print(f"round:{r}")
- casualties=combatphases(hero, r)
- for casualty in casualties:
- del casualty
- def combatpreparation(hero):
- enemies=[]
- allies=[]
- count=0
- number_of_enemies=np.random.randint(5,10)
- number_of_allies=np.random.randint(1,5)
- for en in range(number_of_enemies):
- count+=1
- name=f"enemy {count}"
- gender=random.choice(["male", "female"])
- enemy=Enemy(name, gender)
- enemy.health=np.random.randint(5, 10)
- enemy.damage=np.random.randint(2,8)
- enemy.resistance=enemy.health/2
- enemies.append(enemy)
- for al in range(number_of_allies):
- count+=1
- name=f"ally {count}"
- gender=random.choice(["male", "female"])
- ally=Ally(name, gender)
- ally.health=np.random.randint(10,15)
- ally.damage=np.random.randint(1,5)
- ally.resistance=ally.health/3
- allies.append(ally)
- return allies, enemies
- def combatphases(hero, r):
- combat1=[]
- combat2=[]
- enemies=[]
- allies=[]
- attacks=[]
- for i in range(1,r):
- allies, enemies=combatpreparation(hero)
- allies.append(hero)
- for ally in allies:
- combat1.append({ally.name: (ally.health, ally.damage)})
- for enemy in enemies:
- combat2.append({enemy.name: (enemy.health, enemy.damage)})
- for j in combat1:
- ally=random.choice(allies)
- enemy=random.choice(enemies)
- count=0
- if ally==hero:
- if count<2:
- decide=input("Press Y to use cleave: ")
- count+=1
- if decide=="Y":
- print(f"{hero.name} uses cleave")
- hero.health+=1
- attacking=attack(ally, enemy, True)
- attacking=attack(ally,enemy)
- else:
- pass
- else:
- attacking=attack(ally,enemy)
- attacks.append(attacking)
- hero.health+=1
- for k in combat2:
- hero.health+=1
- ally=random.choice(allies)
- enemy=random.choice(enemies)
- attacked=attack(enemy, ally)
- attacks.append(attacked)
- return attacks
- def attack(attacker, attacked, cleave=False):
- res=""
- luck1=random.choice([1,2,3,4])
- luck2=random.choice([1,2,3])
- damage=attacker.damage*luck2
- if cleave==False:
- damage=damage/luck1
- else:
- damage=damage+2
- health=attacked.health
- attacked.health=health-damage
- if attacked.health>0:
- print(f"{attacker.name} attacks {attacked.name}:{health} with a normal attack causing {damage} damage")
- return Character("none","None")
- else:
- print(f"{attacker.name} deals a mortal blow to {attacked.name}. {attacked.name} dies!")
- res=attacked
- return res
- def attr():
- health=hlth()
- damage=10-(health/10)
- resistance=health/2
- return health, damage, resistance
- def hlth():
- try:
- health=int(input("health min 10 max20: "))
- if 20<health or health<10:
- hlth()
- else:
- return health
- except:
- hlth()
- def gn():
- gender=input("Gender: ")
- if gender!="male" and gender!="female":
- gn()
- else:
- return gender
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement