Untitled
unknown
plain_text
9 months ago
3.1 kB
2
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}), "Gribbler": Character("Gribbler", 80, {"Fireball": 25, "Ice Blast": 20, "Lightning Bolt": 30}), "Necromancer": Character("Necromancer", 90, {"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 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 action_choice == 2: enemy_attack_chance = 2.6 else: enemy_attack_chance = 1.6 if random.random() < enemy_attack_chance: 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!") if __name__ == "__main__": main()
Editor is loading...
Leave a Comment