A few questions

Started by
4 comments, last by KellerHood 12 years, 6 months ago
You see i have my pokemon class i created below, and im content with how it is right now (even incomplete), but i cannot wrap my mind around how to create and implement the pokemons attacks. i could use a function and have pokemon have pointers to use the attacks, i could have a data structure contain all of them and have each pokemon get their attacks from that data structure...any ideas on what would be the easiest way? also a pokemon can only have four attacks would a simple array be sufficient on limiting the amount of attacks it can have?



#pragma once

//pokemon class
class pokemon
{
public:
int m_basehp, m_baseatk, m_basedef, m_basesatk, m_basesdef, m_basespe;

int m_hpev, m_atkev, m_defev, m_satkev, m_sdefev, m_speev;

int m_hpiv, m_atkiv, m_defiv, m_satkiv, m_sdefiv, m_speiv;

int m_level, m_next_level;

bool m_slow, m_medium, m_fast;

void m_level_system();

void m_calculate_hp();

void m_calculate_atk();

void m_calculate_def();

void m_calculate_satk();

void m_calculate_sdef();

void m_calculate_spe();

void m_accuracy();

void m_evasiveness();

void m_attacks();

};

//pokemon objects------------------------------------------------

pokemon bulbasaur;

pokemon ivysaur;

pokemon venasaur;

pokemon charmander;

pokemon charmeleon;

pokemon charizard;

pokemon squirtle;

pokemon wartortle;

pokemon blastoise;

//pokemon base stat declaration----------------------------------

bulbasaur.m_baseatk=0;

//pokemon function definitions------------------------------------

void m_level()//function for level system
{
int m_level_array[99];

int m_level=1;

int m_next_level=2;
}

void m_calculate_hp()//function that calculates a pokemons' health
{

}

void m_calculate_atk()//function that calculates a pokemons' attack
{

}

void m_calculate_def()//function that calculates a pokemons' defense
{

}

void m_calculate_satk()//function that calculates a pokemons' special attack
{

}

void m_calculate_sdef()//function that calculates a pokemons' special defense
{

}

void m_calculate_spe()//function that calculates a pokemons' speed
{

}

void m_attacks()
{

}
Advertisement
Since the amount of attacks per pokemon is guaranteed to be fixed, I don't see any reason not to go with a static array of 4. I would make a base attack class with an overridable attack/action (all attacks aren't acutally attacks) function. Then extend the class for each attack and override the attack function. The pokemon class would have functions for adding an attack at a specified index (0-3) and removing an attack in the same way.

P.S. Good luck. I've always wanted to make a pokemon game too.
I don't think the code you pasted is going to work the way you want it to. Your definitions aren't associated with the pokemon class (via the scope resolution operator :: ). If that's your intent, forget what I said. It just seems like it's not, since the class declaration has matching method names.
What I would do is create a data structure for an attack along the lines of:

typedef struct
{
attacks index;
float power;
float accuracy;
types type;
int pp;
} attack;


Where 'index' is from an enumeration of all the different moves, like:

enum attacks
{
tackle,
leer,
slash,
withdraw,
screech,
etc.
};

And then do the same with 'type'. (enum types {grass, fire, water, flying, electric, etc.};)

Then, create a list of all the attacks like so:

attack at_tackle =
{
tackle,
30,
90,
normal,
35
};



And then have a function in your pokemon class that takes one of these at_ structs and uses it's data to carry out it's attack:

void useAttack(attack at, pokemon opponent)
{
if (at.type == opponent.type)
opponent.hp -= at.power;
if(at.type > opponent.type)
opponent.hp -= at.power*1.5;

//or whatever the calculations are here
}

//use it like this
mypokemon.useAttack(at_tackle, otherpokemon);




Creating an entirely new class just for an attack is going a bit overboard with classes, in my humble C-programmer's opinion.
@ Homer, my thoughts exactly. .@ Feeix, awesome :D! So im wondering can i use a conditional loop like an if loop when a certain pokemon reaches a certain level and have that if loop ask whether or not i want to teach a pokemon a new attack?

@ Homer, my thoughts exactly. .@ Feeix, awesome :D! So im wondering can i use a conditional loop like an if loop when a certain pokemon reaches a certain level and have that if loop ask whether or not i want to teach a pokemon a new attack?


Yeah, but alter this code here wherever you use it:



//use it like this
mypokemon.useAttack(at_tackle, otherpokemon);


to


//use it like this
mypokemon.useAttack(mypokemon.myattacks[1], otherpokemon); //attacks is a static array with a length of 4



Have your pokemon have a static array with 4 elements, one for each attack.
Declare it like this:


attack myattacks[4];
myattacks[0] = at_whatever; //from the enumerator
//and so on with the other 3.


Then, when your pokemon levels up, and you want to change the attack, just swap out the variable.

myattacks[0] = at_theattackyouwanttolearn;


Keep in mind however, that this is just syntactically correct pseudocode. You'll need to modify it to fit your classes and your structure.

This topic is closed to new replies.

Advertisement