Untitled

 avatar
unknown
plain_text
10 months ago
3.0 kB
3
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, "Rush": 12}

    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, "Stunning Strike": 30}),
        "Rogue": Character("Rogue Bandit", 95, {"Poison Trap ": 15, "Pocket Sand ": 20, "Dagger Spread": 22}),
        "Mage": Character("Mage", 80, {"Fireball": 20, "Ice Shards": 24, "Thundercrash": 30,}),

    }

    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):
            print(f'{i}. {ability}')
        action_name = int(input('Enter the number for your action '))
        action_name = list(chosen_character.abilities.keys()) [action_choice-1]
        damage = chosen_character.attack(action_name)

        print(f'\nYou use {action_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