Ravi
unknown
plain_text
a year ago
2.7 kB
8
Indexable
import random class Character: def __init__(self,name,hp,attack_power, attack_names, attack_multipliers): self.name = name self.hp = hp self.attack_power = attack_power self.attack_names = attack_names self.attack_multipliers = attack_multipliers def attack(self, other, attack_name): multiplier = self.attack_multipliers[self.attack_names.index(attack_name)] damage= random.randint(1, self.attack_power) * multiplier other.hp -= damage return damage, attack_name def game(): player= Character( name= "Faze_fulldiddy", hp=160, attack_power=37, attack_names = ["diddy party, Full diddy experience"], attack_multipliers=[1, 1.5] # Diddy party has 1x damage, full diddy expereince has 1.5x damag ) enemy= Character(name= "Stretchy Sketch", hp=130, attack_power=40, attack_names = ["OF video, Going in the deep end"], attack_multipliers=[1, 1.5] # OF has 1x damage, Going in the deep end has 1.5x damage ) print (" welcome to my diddy ah RPG games") print (f" you are {player.name} with {player.hp} HP!/n") print (f"an enemy {enemy.name} appears with {enemy.hp} HP!/n") while player.hp > 0 and enemy. hp > 0 : action = input ("do you want to [a]ttack or [r]un away?: ").strip().lower() if action == 'a' : print (f"choose your attack:[1] {player.attack_names[0]} or [2] {player.attack_names[1]}") attack_choice= input ("eneter your attack choice") if action == '1': attack_choice = player.attack_names[0] elif action == '2': attack_choice = player.attack_names[1] else: print ("Invalid Choice,you lost your turn") continue damage, attack_name = player.attack(enemy, attack_name) print (f"you use {attack_name} and attack the {enemy.name} for {damage}damage.") if enemy.hp>0: print (f"The {enemy.name} has {enemy.hp} HP left.") else: print (f"The{enemy.name} is defeated.") attack_name = random.choice (enemy.attack_names) damage, attack_name = enemy.attack(player, attack_name) print(f"The{enemy.name}uses {attack_name} and attacks you for {damage}damage") if player.hp > 0: print (f"you have{player.hp} HP left") else: print ("you are defeated!") break elif action == "r": print("you ran away!") break else: print ("invalid action. Please choose 'a'or 'r' to run. ") print("game over") if __name__ == "__main__" : game()
Editor is loading...
Leave a Comment