Untitled
unknown
plain_text
a year ago
3.0 kB
5
Indexable
import random class Character: def __init__(self, name, health, abilities): self.name = name self.health = health self.max_health = health self.abilities = abilities def attack(self, ability): return self.abilities[ability] def heal(self): heal_amount = 20 self.health = min(self.max_health, self.health + heal_amount) return heal_amount class Enemy: def __init__(self, health): self.health = health self.attacks = {"swipe": 15, "stomp": 20, "roar": 10} def attack(self): attack_name = random.choice(list(self.attacks.keys())) return attack_name, self.attacks[attack_name] def main(): characters = { "Warrior": Character("Warrior", 100, {"slash": 20, "shield bash": 15, "power strike": 25}), "Isabel": Character("Isabel", 100, {"fireball": 25, "ice blast": 20, "lightning bolt": 30}), "Necromancer": Character("Necromancer", 100, {"resurrect": 25, "poison dart": 15, "shadow strike": 20}) } print("Choose your character:") for i, char in enumerate(characters.keys(), start=1): print(f"{i}. {char}") choice = int(input("Enter the number of your choice: ")) chosen_character = list(characters.values())[choice - 1] enemy = Enemy(100) while chosen_character.health > 0 and enemy.health > 0: print(f"\nYour Health: {chosen_character.health}") print(f"Enemy Health: {enemy.health}") print("Choose your option:") print("1. Attack") print("2. Heal") action_choice = int(input("Enter the number of your choice: ")) if action_choice == 1: print("Choose your attack:") for i, ability in enumerate(chosen_character.abilities.keys(), start=1): print(f"{i}. {ability}") attack_choice = int(input("Enter the number of your attack: ")) attack_name = list(chosen_character.abilities.keys())[attack_choice - 1] damage = chosen_character.attack(attack_name) print(f"\nYou use {attack_name}, dealing {damage} damage!") enemy.health -= damage if enemy.health <= 0: print("You have defeated the enemy!") break elif action_choice == 2: heal_amount = chosen_character.heal() print(f"\nYou heal for {heal_amount} health points!") else: print("Invalid action. You lose your turn.") continue if enemy.health > 0: enemy_attack_name, enemy_damage = enemy.attack() print(f"The enemy uses {enemy_attack_name}, dealing {enemy_damage} damage!") chosen_character.health -= enemy_damage if chosen_character.health <= 0: print("You have been defeated by the enemy!") if __name__ == "__main__": main()
Editor is loading...
Leave a Comment