Untitled
unknown
plain_text
a year ago
2.7 kB
7
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.int(1, self.attack_power) * multiplier other.hp -= damage return damage, attack_name def game(): player = Character( name = "Chinese Gorllia", hp = 40, attack_power = 20, attack_names = ["Sit on", "Devour"], attack_multipliers = [1,1.5] ) enemy = Character( name = "Chinese Faaaaatty", hp = 80, attack_power = 26, attack_names = ["Sit on", "Devour"], attack_multipliers = [1.25,1.5] ) print(f"You are {player.name} with {player.hp} HP") print(f"Your enemy is aa {enemy.name} with {player.hp} HP") 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"Choos eyour attack; [1] {player.attack_names[0]} or [2] {player.attack_names[1]}") attack_choice = input("Enter 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 used {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.") break 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' to attack or 'r' to run") print("Game Over") if __name__ == "__main__": game()
Editor is loading...
Leave a Comment