Facebook
From aa, 10 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 281
  1.  
  2. class Entity:
  3.     def __init__(self):
  4.         self.name = "Enemy"
  5.         self.race = None
  6.         self._class = None
  7.         self.str = 10
  8.         self.dex = 10
  9.         self.con = 10
  10.         self.ac = 10
  11.         self.wep = Weapon()
  12.         self.arm = Armor()
  13.         self.lvl = 0
  14.         self.xp = 0
  15.         self.hp = 10 + (self.lvl * (self.con // 2))
  16.        
  17.     '''def __str__(self):
  18.        return str(f"{self.name}\nHP: {self.hp}\n" +
  19.               f"STR: {self.str}\nDEX: {self.dex}\n" +
  20.               f"CON: {self.con}\nLVL: {self.lvl}\n" +
  21.               f"AC: {self.ac}\n"
  22.               f"XP: {self.xp} / {self.xp_to_lvlup()}\n\n" +
  23.               f"{self.wep}\n{self.arm}\n")'''
  24.        
  25.     def xp_to_lvlup(self):
  26.         return 20 + (self.lvl * 80)
  27.        
  28.     def lvlup(self):
  29.         while self.xp >= self.xp_to_lvlup():
  30.             self.level += 1
  31.             self.hp += (self.con / 5) + 4
  32.             self.xp -= self.xp_to_lvlup()
  33.         print(f"You have leveled up to: {self.level}")
  34.        
  35.     def take_damage(self, amount):
  36.         self.hp -= amount
  37.        
  38.     def get_damage(self):
  39.         return self.str + self.weapon.damage
  40.        
  41.     def attack(self, target):
  42.         target.hp -= self.get_damage()
  43.         print(f"{self.name} attacks {target.name} for {self.get_damage()} damage\n")
  44.        
  45.     def equip_weapon(self, weapon):
  46.         self._old_weapon = self.weapon
  47.         self.weapon = weapon
  48.         print(f"{self.name} has thrown away {self._old_weapon} and equipped {self.weapon}")
  49.        
  50.     def equip_armor(self, armor):
  51.         self._old_armor = self.armor
  52.         self.armor = armor
  53.         print(f"{self.name} has thrown away {self._old_armor} and equipped {self.armor}")
  54.        
  55.     def is_dead(self):
  56.         if self.hp <= 0:
  57.             return True
  58.         return False
  59.        
  60.  
  61. class Player(Entity):
  62.     def __init__(self, name, race, _class, wep, arm):
  63.         super().__init__()
  64.         self.name = name
  65.         self.race = race
  66.         self._class = _class
  67.         self.wep = wep
  68.         self.arm = arm
  69.         self.lvl = 1
  70.         self.xp = 0
  71.        
  72.        
  73. class Enemy(Entity):
  74.     def __init__(self, race, _class, wep, arm):
  75.         super().__init__()
  76.         self.name += f" {race}"
  77.         self.race = race
  78.         self._class = _class
  79.         self.wep = wep
  80.         self.arm = arm
  81.         self.hp = 10
  82.         self.lvl = 1
  83.         self.xp = 20
  84.  
  85.  
  86. class Human(Entity):
  87.     def __init__(self):
  88.         super().__init__()
  89.         self.str += 0
  90.         self.dex += 0
  91.         self.con += 0
  92.        
  93.    
  94. class Orc(Entity):
  95.     def __init__(self):
  96.         super().__init__()
  97.         self.str += 2
  98.         self.dex -= 2
  99.        
  100.    
  101.        
  102. class Barbarian(Entity):
  103.     def __init__(self):
  104.         super().__init__()
  105.         self.str += 6
  106.         self.dex += 2
  107.         self.con += 4
  108.        
  109.     def __str__(self):
  110.         return "Barbarian"
  111.  
  112. class Rogue(Entity):
  113.     def __init__(self, race, wep, arm):
  114.         super().__init__(race, _class, wep, arm)
  115.         self.str += 2
  116.         self.dex += 6
  117.         self.con += 4
  118.      
  119.        
  120. class Weapon:
  121.     def __init__(self):
  122.         self.type = "Fists"
  123.         self.damage = 1
  124.         self.weight = 1
  125.         self.level = 1
  126.        
  127.     def __str__(self):
  128.         return str(f"WEAPON\n{self.type}\nDamage: {self.damage}\n" +
  129.         f"Weight: {self.weight}\nLevel: {self.level}\n")
  130.        
  131.     def upgrade():
  132.         if self.level < 10:
  133.             self.damage += 2
  134.             self.level += 1
  135.        
  136.            
  137. class Sword(Weapon):
  138.     def __init__(self):
  139.         super().__init__()
  140.         self.type = "Sword"
  141.         self.damage += 4
  142.         self.weight += 4
  143.        
  144.        
  145. class Armor():
  146.     def __init__(self):
  147.         self.type = "Rags"
  148.         self.ac = 10
  149.        
  150.     def __str__(self):
  151.         return str(f"ARMOR\n{self.type}\nAC: {self.ac}\n")
  152.        
  153.  
  154. class Mail(Armor):
  155.     def __init__(self):
  156.         super().__init__()
  157.         self.ac += 2
  158.        
  159.        
  160. def game():
  161.     while True:
  162.          acti Your Action\n" + \
  163.        "(search, fight, run, end)\n")
  164.        if action:
  165.            pass
  166.        if p1.is_dead():
  167.            print("Game over")
  168.            break
  169.         if acti 'end':
  170.            print("Ending the Game")
  171.            break
  172.        
  173. def show_stats(entity):
  174.    print(f"{entity.name}\nHP: {entity.hp}\n" +
  175.               f"STR: {entity.str}\nDEX: {entity.dex}\n" +
  176.               f"CON: {entity.con}\nLVL: {entity.lvl}\n" +
  177.               f"AC: {entity.ac}\n"
  178.               f"XP: {entity.xp} / {entity.xp_to_lvlup()}\n\n" +
  179.               f"{entity.wep}\n{entity.arm}\n")
  180.            
  181.        
  182. e1 = Enemy(Orc(), Barbarian(), Weapon(), Armor())
  183. show_stats(e1)