Start New Discussion within our Software Development Community

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!")

#then to call it when they ask for slam

attack = str(input("OPTIONS: SLAM"))
if attack == "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):

    def attack(self,power,enemy):

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):

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


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


Good luck!

This article has been dead for over six months. Start a new discussion instead.