Skip to content

Instantly share code, notes, and snippets.

@lb7n
Last active February 5, 2020 22:17
Show Gist options
  • Save lb7n/7c976a3128b13f2e225af94a66a68121 to your computer and use it in GitHub Desktop.
Save lb7n/7c976a3128b13f2e225af94a66a68121 to your computer and use it in GitHub Desktop.
def get_all_subclasses(cls):
all_subclasses = []
for subclass in cls.__subclasses__():
all_subclasses.append(subclass.__name__)
all_subclasses.extend(get_all_subclasses(subclass))
return all_subclasses
class Character:
def __init__(self, strength):
self.health = 50
self.strength = strength
self.weapon = weapon
def battle(self, other_character):
if self.strength > other_character.strength:
other_character.health -= 20
print(f"I was victorious!")
else:
self.health -= 20
print(f"I will triumph next time!")
class Warlock(Character):
pass
class Druid(Character):
pass
class Shaman(Character):
pass
class DeathKnight(Character):
pass
class DemonHunter(Character):
pass
class Hunter(Character):
pass
class Priest(Character):
pass
class Paladin(Character):
pass
class Mage(Character):
def __init__(self):
# super().__init__(strength)
self.health = 40
self.mana = 100
self.weapon = "fist"
def status_report(self):
print(f"I am a Wizard. My Health is {self.health}. You shall not pass.")
class Warrior(Character):
def __init__(self, strength):
super().__init__(strength)
self.health = 70
self.weapon = "fist"
def status_report(self):
print(f"I am a Warrior. My Health is {self.health}. ")
class Weapon:
def __init__(self):
self.damage = damage
self.hands = hands
class Fist(Weapon):
def __init__(self):
self.damage = randrange(0,7,1)
self.hands = 2
class StarterStaff:
def __init__(self):
super().__init__(damage)
self.damage = randrange(0,12,2)
super().__init__(hands)
self.hands = 2
def randomCharacter():
for randomNumb in range(1):
if randomNumb == 0:
return Mage()
elif randomNumb == 1:
return Warrior()
print(f"Welcome to Azeroth! Choose your class from the list: {', '.join(get_all_subclasses(Character))}")
player_character = input("Who will you play as?")
if player_character.capitalize() in get_all_subclasses(Character):
print(f"Awesome! You are now: {player_character}")
character = eval(player_character)()
print(character.status_report())
else:
print("not a valid input")
print(f"A wild {randomCharacter()} appears!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment