Untitled
unknown
plain_text
2 years ago
4.1 kB
8
Indexable
import re from inspect import getmembers, isfunction class Undead: def __init__(self, name): self.name = name self.hp = 100 self.state = "Alive" class Zombie(Undead): def __init__(self, name): super().__init__(name) def eat(self, obj): if self.hp > 50: self.hp = obj / 2 obj.hp = obj / 2 print("Opponent name: {obj.name}") print("Opponent HP: {obj.hp}") print("Opponent State: {obj.state}") else: print(f"{self.name} cannot eat {obj.name} your hp is less than 50") class Vampire(Undead): def __init__(self, name): super().__init__(name) class Skeleton(Undead): def __init__(self, name): super().__init__(name) class Ghost(Undead): def __init__(self, name): super().__init__(name) class Lich(Undead): def __init__(self, name): super().__init__(name) class Mummy(Undead): def __init__(self, name): super().__init__(name) def instantiate_undead(category, name): if "a" in category: print("You chose Zombie!") if name == "" or name is None: return Zombie("zombie") else: return Zombie(name + " - zombie") elif "b" in category: print("You chose Vampire!") if name == "" or name is None: return Vampire("vampire") else: return Vampire(name + " - vampire") elif "c" in category: print("You chose Skeleton!") if name == "" or name is None: return Skeleton("skeleton") else: return Skeleton(name + " - skeleton") elif "d" in category: print("You chose Ghost!") if name == "" or name is None: return Ghost("ghost") else: return Ghost(name + " - ghost") elif "e" in category: print("You chose Lich!") if name == "" or name is None: return Ghost("Lich") else: return Ghost(name + " - lich") elif "f" in category: print("You chose Mummy!") if name == "" or name is None: return Ghost("Mummy") else: return Ghost(name + " - Mummy") print("================================") print(" Undead Game Menu ") print("================================") print("Choose your chosen undead: ") print(" a. Zombie") print(" b. Vampire") print(" c. Skeleton") print(" d. Ghost") print(" e. Lich") print(" f. Mummy \n") category = input("Enter your choice: ") is_name_customized = input("Do you want to customize your name? Y/N: ") if re.search(is_name_customized, "N", re.IGNORECASE): player = instantiate_undead(category, "") else: custom_name = input("Enter your name: ") player = instantiate_undead(category, custom_name) print("Your undead name is: " + player.name + "\n") undead_list = [player, Zombie("Zombie"), Vampire("Vampire"), Skeleton("Skeleton"), Ghost("Ghost"), Lich("Lich"), Mummy("Mummy")] choice = "" while (choice != "c"): if "a" in choice: count = 0 for undead in undead_list: print(undead.name) properties = [method for method in dir(undead) if method.startswith('__') is False] for ability in properties: if ability not in ["name", "hp", "state"]: print(f" Ability: {ability}") for ud in undead_list: if ud.name != undead.name: count = count + 1 print(f" {count} use on {ud.name}") elif "b" in choice: for undead in undead_list: print(undead.name) print(f"HP: {undead.hp}") print(f"State: {undead.state} \n") print(" a. Command Undead") print(" b. Display Undead") print(" c. Quit \n") choice = input("Enter your choice: ") print()
Editor is loading...