Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.6 kB
2
Indexable
Never

# Define a class for Pokemon
class Pokemon:
    def __init__(self, name, type, hp, attack, defense, moves):
        self.name = name
        self.type = type
        self.hp = hp
        self.attack = attack
        self.defense = defense
        self.moves = moves  # A dictionary with move names and damage values

    def __str__(self):
        return f"{self.name} ({self.type}) - HP: {self.hp}"

    def take_damage(self, damage):
        self.hp -= damage
        if self.hp < 0:
            self.hp = 0

    def is_fainted(self):
        return self.hp <= 0


# Define a function to simulate a battle
def battle(pokemon1, pokemon2):
    print(f"A wild {pokemon2.name} appeared!")
    while not pokemon1.is_fainted() and not pokemon2.is_fainted():
        # Pokemon1 attacks Pokemon2
        move = random.choice(list(pokemon1.moves.keys()))
        damage = pokemon1.moves[move] * (pokemon1.attack / pokemon2.defense)
        print(f"{pokemon1.name} used {move}! It dealt {damage:.1f} damage.")
        pokemon2.take_damage(damage)

        if pokemon2.is_fainted():
            print(f"{pokemon2.name} fainted! {pokemon1.name} wins!")
            break

        # Pokemon2 attacks Pokemon1
        move = random.choice(list(pokemon2.moves.keys()))
        damage = pokemon2.moves[move] * (pokemon2.attack / pokemon1.defense)
        print(f"{pokemon2.name} used {move}! It dealt {damage:.1f} damage.")
        pokemon1.take_damage(damage)

        if pokemon1.is_fainted():
            print(f"{pokemon1.name} fainted! {pokemon2.name} wins!")
            break
Leave a Comment