class Entity:
def __init__(self):
self.name = "Enemy"
self.race = None
self._class = None
self.str = 10
self.dex = 10
self.con = 10
self.ac = 10
self.wep = Weapon()
self.arm = Armor()
self.lvl = 0
self.xp = 0
self.hp = 10 + (self.lvl * (self.con // 2))
'''def __str__(self):
return str(f"{self.name}\nHP: {self.hp}\n" +
f"STR: {self.str}\nDEX: {self.dex}\n" +
f"CON: {self.con}\nLVL: {self.lvl}\n" +
f"AC: {self.ac}\n"
f"XP: {self.xp} / {self.xp_to_lvlup()}\n\n" +
f"{self.wep}\n{self.arm}\n")'''
def xp_to_lvlup(self):
return 20 + (self.lvl * 80)
def lvlup(self):
while self.xp >= self.xp_to_lvlup():
self.level += 1
self.hp += (self.con / 5) + 4
self.xp -= self.xp_to_lvlup()
print(f"You have leveled up to: {self.level}")
def take_damage(self, amount):
self.hp -= amount
def get_damage(self):
return self.str + self.weapon.damage
def attack(self, target):
target.hp -= self.get_damage()
print(f"{self.name} attacks {target.name} for {self.get_damage()} damage\n")
def equip_weapon(self, weapon):
self._old_weapon = self.weapon
self.weapon = weapon
print(f"{self.name} has thrown away {self._old_weapon} and equipped {self.weapon}")
def equip_armor(self, armor):
self._old_armor = self.armor
self.armor = armor
print(f"{self.name} has thrown away {self._old_armor} and equipped {self.armor}")
def is_dead(self):
if self.hp <= 0:
return True
return False
class Player(Entity):
def __init__(self, name, race, _class, wep, arm):
super().__init__()
self.name = name
self.race = race
self._class = _class
self.wep = wep
self.arm = arm
self.lvl = 1
self.xp = 0
class Enemy(Entity):
def __init__(self, race, _class, wep, arm):
super().__init__()
self.name += f" {race}"
self.race = race
self._class = _class
self.wep = wep
self.arm = arm
self.hp = 10
self.lvl = 1
self.xp = 20
class Human(Entity):
def __init__(self):
super().__init__()
self.str += 0
self.dex += 0
self.con += 0
class Orc(Entity):
def __init__(self):
super().__init__()
self.str += 2
self.dex -= 2
class Barbarian(Entity):
def __init__(self):
super().__init__()
self.str += 6
self.dex += 2
self.con += 4
def __str__(self):
return "Barbarian"
class Rogue(Entity):
def __init__(self, race, wep, arm):
super().__init__(race, _class, wep, arm)
self.str += 2
self.dex += 6
self.con += 4
class Weapon:
def __init__(self):
self.type = "Fists"
self.damage = 1
self.weight = 1
self.level = 1
def __str__(self):
return str(f"WEAPON\n{self.type}\nDamage: {self.damage}\n" +
f"Weight: {self.weight}\nLevel: {self.level}\n")
def upgrade():
if self.level < 10:
self.damage += 2
self.level += 1
class Sword(Weapon):
def __init__(self):
super().__init__()
self.type = "Sword"
self.damage += 4
self.weight += 4
class Armor():
def __init__(self):
self.type = "Rags"
self.ac = 10
def __str__(self):
return str(f"ARMOR\n{self.type}\nAC: {self.ac}\n")
class Mail(Armor):
def __init__(self):
super().__init__()
self.ac += 2
def game():
while True:
acti Your Action\n" + \
"(search, fight, run, end)\n")
if action:
pass
if p1.is_dead():
print("Game over")
break
if acti 'end':
print("Ending the Game")
break
def show_stats(entity):
print(f"{entity.name}\nHP: {entity.hp}\n" +
f"STR: {entity.str}\nDEX: {entity.dex}\n" +
f"CON: {entity.con}\nLVL: {entity.lvl}\n" +
f"AC: {entity.ac}\n"
f"XP: {entity.xp} / {entity.xp_to_lvlup()}\n\n" +
f"{entity.wep}\n{entity.arm}\n")
e1 = Enemy(Orc(), Barbarian(), Weapon(), Armor())
show_stats(e1)