Untitled
unknown
python
2 years ago
1.0 kB
10
Indexable
# Define the Player class class Player: def __init__(self): # Set the player's starting stats self.hp = 100 self.attack = 10 self.defense = 10 self.speed = 10 # Set the player's starting Pokemon self.pokemon = "Charmander" # Define the attack method def attack(self, enemy): # Calculate the damage done to the enemy damage = self.attack - enemy.defense # Deal the damage to the enemy enemy.hp -= damage # Print a message showing the attack and damage done print(f"{self.pokemon} attacked {enemy.name} and did {damage} damage!") # Define the Enemy class class Enemy: def __init__(self, name, hp, attack, defense, speed): # Set the enemy's stats self.name = name self.hp = hp self.attack = attack self.defense = defense self.speed = speed # Create a player and enemy player = Player() enemy = Enemy("Pidgey", 50, 5, 5, 5) # Have the player attack the enemy player.attack(enemy)
Editor is loading...