Untitled
unknown
python
a year ago
12 kB
2
Indexable
Never
import re class Undead: def __init__(self, name=None, hp=None): if name != None and hp != None: self.__hp = hp self.__name = "Undead" + name else: self.__hp = 100 self.__name = "Undead" self.__isDead = False # dead is a boolean def isDead(self, dead=None): if dead == None: return self.__isDead else: self.__isDead = dead def getName(self): return self.__name def getHP(self): return self.__hp def setName(self, name): self.__name = name def setHP(self, hp=None, multiplier=None): if multiplier == None: self.__hp = hp else: self.__hp = self.__hp * multiplier class Zombie(Undead): def __init__(self, name=None, hp=None): super().__init__(name= name, hp =hp) if name != None: super().setName("Zombie" + name) else: super().setName("Zombie" + name) def eat(self,Ename,EHP): super().setHP((EHP * 0.5)+super().getHP()) print(f"{super().getName()}us eat on{Ename}") print(f"{super().getName()},HP:{super().getHP()}") print(f"{Ename}HP:{EHP}") def attack(self, EHP): return EHP - (super().getHP()*0.5) class Vampire(Undead): def __init__(self, name=None, hp=None): super().__init__(name=None, hp=None) if name != None: super().setName("Vampire" + name) else: super().setName("Vampire" + name) super().setHP(120) #bite ability def bite(self,Ename,EHP): super().setHP((EHP * 0.8) + super().getHP()) print(f"{super().getName()} us eat on {Ename}") print(f"{super().getName()},HP:{super().getHP()}") print(f"{Ename}HP:{EHP}") #attack def attack(self,EHP): return EHP - self.getHP() class Skeleton(Undead): def __init__(self, name=None, hp=None): super().__init__(name= name, hp =hp) if name != None: super().setName("Skeleton" + name) else: super().setName("Skeleton" + name) super().setHP(80) def attack(self, EHP): return EHP - (super().getHP()*0.7) class Ghost(Undead): def __init__(self, name=None, hp=None): super().__init__(name= name, hp =hp) if name != None: super().setName("Ghost" + name) else: super().setName("Ghost"+name) super().setHP(50) def hunt(self,Ename,EHP): super().setHP((EHP * 0.1)+super().getHP()) print(f"{super().getName()} us eat on {Ename}") print(f"{super().getName()},HP:{super().getHP()}") print(f"{Ename}HP:{EHP}") def attack(self, EHP): return EHP - (super().getHP()*0.2) class Lich(Skeleton): def __init__(self, name=None, hp=None): super().__init__(name= name, hp =hp) if name != None: super().setName("Lich" + name) else: super().setName("Lich" + name) def spell(self,Ename,EHP): super().setHP((EHP * 0.1) + super().getHP()) print(f"{super().getName()} us spell on {Ename}") return EHP *0.1 class Mummy(Zombie): def __init__(self, name=None, hp=None): super().__init__(name= name, hp =hp) if name != None: super().setName("Mummy" + name) else: super().setName("Mummy" + name) # return EHP.getHP() def attack(self, EHP): if isinstance(EHP, Ghost): # if Ghost will be attacked EHP.setHP(EHP.getHP() - ((self.getHP() * 0.5) + (EHP.getHP() * 0.10)) * 0.10) else: EHP -= (self.getHP() * 0.5) + (EHP * 0.10) return EHP print("=============================================") print(" W E L C O M E T O T H E U N D E A D ") print("=============================================") arr = [] x = int(0) while x != 4: print("\n[1] Create UNDEAD") print("[2] Command") print("[3] Display") x = int(input("\nYour Choice: ")) if x == 1: print("\n" + "===========================") print(" Undead Game Menu ") print("===========================") print("Choose your Undead") print(" a. Zombie") print(" b. Vampire") print(" c. Skeleton") print(" d. Ghost ") print(" e. Lich") print(" f. Mummy ") c = input("Enter your choice: ") print(" ") if re.search(c, "a", re.IGNORECASE): num = int(input("How many Zombie/s do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Zombie(name="-" + name)) else: arr.append(Zombie(str(i + 1))) elif re.search(c, "b", re.IGNORECASE): num = int(input("How many Vampire/s do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Vampire(name="-" + name)) else: arr.append(Vampire(str(i + 1))) elif re.search(c, "c", re.IGNORECASE): num = int(input("How many Skeleton/s do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Skeleton(name="-" + name)) else: arr.append(Skeleton(str(i + 1))) elif re.search(c, "d", re.IGNORECASE): num = int(input("How many Ghost/s do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Ghost(name="-" + name)) else: arr.append(Ghost(str(i + 1))) elif re.search(c, "e", re.IGNORECASE): num = int(input("How many Lich/es do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Lich(name="-" + name)) else: arr.append(Lich(str(i + 1))) elif re.search(c, "f", re.IGNORECASE): num = int(input("How many Mummy/ies do you want to print? ")) for i in range(num): customize = input("Do you want to customize name Y/N - ") if re.search(customize, "Y", re.IGNORECASE): name = input() arr.append(Mummy(name="-" + name)) else: arr.append(Mummy(str(i + 1))) elif x == 2: print("\nWhich one do you want to command?") for j, print_undead in enumerate(arr): print(f"[{j+1}] {arr[j].getName()}") undead_index = enumerate(arr) undead_attacker = int(input("Please choose an undead: ")) undead_attacker = undead_attacker - 1 for k, index in enumerate(arr): if undead_attacker == k: print("You have selected:", arr[k].getName(), "To attack!") else: continue # select skill area # for i in range(len(arr)): ability = [] properties = [method for method in dir(arr[k])] for y in properties: if y in ["attack", "spell", "hunt", "eat", "bite"]: ability.append(y) print(f"Name: {arr[k].getName()}") for z in range(len(ability)): print(f"{z + 1} {ability[z]}") move = int(input("Which move would you like to use?")) - 1 print("Choose which undead you want to attack:") for undead, undead_obj in enumerate(arr): if arr[k].getName() != arr[undead].getName(): print(f"{undead + 1} {undead_obj.getName()}") enemy = int(input()) - 1 if ability[move] == "attack" and isinstance(arr[enemy], Ghost): print(f"{arr[k].getName()} attacks {arr[enemy].getName()}") arr[enemy].setHP(arr[undead_attacker].attack(arr[enemy].getHP())) print(f"Name: {arr[k].getName()} HP: {arr[k].getHP()}") print(f"Name: {arr[enemy].getName()} HP: {arr[enemy].getHP()}") elif ability[move] == "attack": arr[enemy].setHP(arr[k].attack(arr[enemy].getHP())) print(f"{arr[k].getName()} attacks {arr[enemy].getName()}") print(f"Name: {arr[k].getName()} HP: {arr[k].getHP()}") print(f"Name: {arr[enemy].getName()} HP: {arr[enemy].getHP()}") if isinstance(arr[enemy], Mummy): if arr[enemy].getHP() <= 0: print("HP Reduced to 0. Reviving...") arr[enemy].setHP(100) elif ability[move] == "eat" or ability[move] == "bite" or ability[move] == "hunt" or ability[ move] == "spell": if ability[move] == "eat": arr[k].eat(arr[enemy].getName(), arr[enemy].getHP()) elif ability[move] == "bite": arr[k].bite(arr[enemy].getName(), arr[enemy].getHP()) elif ability[move] == "hunt": arr[k].hunt(arr[enemy].getName(), arr[enemy].getHP()) elif ability[move] == "spell": arr[enemy].setHP(arr[enemy].getHP() - arr[k].spell(arr[enemy].getName(), arr[enemy].getHP())) print(f"Name: {arr[k].getName()} HP: {arr[k].getHP()}") print(f"Name: {arr[enemy].getName()} HP: {arr[enemy].getHP()}") elif x == 3: # print("\n=================================") # print(" CREATED UNDEAD CHARACTERS ") # print("=================================") # for i in range(len(arr)): # print(f"\nName: {arr[i].getName()}") # print(f"HP: {arr[i].getHP()}") # if (isinstance(arr[i],Vampire) or isinstance(arr[i],Lich)): # print("State: Alive") # else: # if arr[i].getHP()<=0: # arr[i].isDead(True) # print("State: Dead") # else: # print("State: Alive") print("\n=================================") print(" CREATED UNDEAD CHARACTERS ") print("=================================") for i in range(len(arr)): print(f"\nName: {arr[i].getName()}") print(f"HP: {arr[i].getHP()}") if isinstance(arr[i], Vampire) or isinstance(arr[i], Lich): print("State: Alive") else: if arr[i].getHP()<=0: arr[i].isDead(True) print("State: Dead") else: print("State: Alive")