Sign in to follow this  
jblevins1991

A few questions

Recommended Posts

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?


[b]
#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()
{

}[/b]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 [b]:: [/b]). If that's your intent, forget what I said. It just seems like it's not, since the class declaration has matching method names.

Share this post


Link to post
Share on other sites
What I would do is create a data structure for an attack along the lines of:
[code]
typedef struct
{
attacks index;
float power;
float accuracy;
types type;
int pp;
} attack;
[/code]

Where 'index' is from an enumeration of all the different moves, like:
[code]
enum attacks
{
tackle,
leer,
slash,
withdraw,
screech,
etc.
};
[/code]
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:
[code]
attack at_tackle =
{
tackle,
30,
90,
normal,
35
};
[/code]


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:
[code]
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);
[/code]



Creating an entirely new class just for an attack is going a bit overboard with classes, in my humble C-programmer's opinion.

Share this post


Link to post
Share on other sites
@ 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?

Share this post


Link to post
Share on other sites
[quote name='jblevins1991' timestamp='1318536760' post='4872290']
@ 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?
[/quote]

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

[code]

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

to
[code]

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


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

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

Then, when your pokemon levels up, and you want to change the attack, just swap out the variable.
[code]
myattacks[0] = at_theattackyouwanttolearn;
[/code]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this