I am creating a pokemon text-based game.
I have 1 problem, I dont know how to do the attacks.
I thought -

enemyHP = 100

class pikachu:
    def slamAttack(self):
        self.enemyHP = enemyHP - 30
        print("pikachu used slam!")
        print(enemyHP)

#then to call it when they ask for slam

attack = str(input("OPTIONS: SLAM"))
if attack == "SLAM":
    pikachu.slam

but i don't know. I would like if someone could just post a simple example of using OOP with this.

thanks for any help

Create a class for a Pokemon in general. Then create instances of that object as the pokemon you control and the ones you have to battle(say a tournament). A simple class for a pokemon would be like this:

class Pokemon(object):
    """A Pokemon object"""

    def __init__(self,name,hp,powers):
        self.name=name
        self.hp=hp
        self.powers=powers

    def attack(self,power,enemy):
        enemy.hp-=power.damage

And create a power object that stores a name and the damage it can do

class Power(object):
    """A object that represents the power of a Pokemon"""

    def __init__(self,name,damage):
        self.name=name
        self.damage=damage

Similarly you can create a trainer object who has a set of Pokemon objects and call these instances in the actual program to simulate each fight
eg:

my_pokemon=Pokemon("Pikachu",100,list_of_powers1)
enemy_pokemon=Pokemon("Someothermon",50,list_of_powers2)

Get the actions from the user and call your pokemon's method to hit

my_pokemon.hit(slam,enemy_pokemon)

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.