class squirtl
{public :
int life = 500;
int stg = 50;
int def = 20;
};
class pikachu
{public :
int life = 600;
int stg = 80;
int def = 10;
};
class charmender
{public :
int life = 600;
int stg = 80;
int def = 10;
};
class pidgey
{public :
int life = 600;
int stg = 80;
int def = 10;
};
squirtl pokemon_y;
pikachu pokemon_x;
do {
void attack();
{
pokemon_y.life = pokemon_y.life - (pokemon_x.stg/pokemon_x.stg);
}
cout << "presse 1 to attack" << endl;
cout << "presse 2 to heal" << endl;
cout << "presse 3 to throw pokeball" << endl;
cin >> x ;
if (x == 1)
void attack();
cout << pokemon_x.life << endl;
cout << pokemon_y.life <<endl;
}
while (pokemon_x.life && pokemon_y.life > 1);
}
what i wanted to do now was creat a player class or array that contains a certain number of pokemons and i need help with doing that, i was thinking of doing somthing like an array player[3]={squirtl,pikachu,charmender} (of course this wouldn't work)
you are making a bit of a mess :)
you should have 1 class, with life, stg, def in it, and the name of the thing as well, not a unique class for each one. Classes are types, like int, and the data changes not the type.
What you have, in terms of int:
typedef int three_t;
typedef int five_t;
three_t three = 3;
five_t five = 5;
instead of just saying
int three = 3;
int five = 5;
class pokey
{public :
string name;
int life;
int stg;
int def;
};
and if you make a constructor for it, you can allocate your array of 3 of them simply -- its similar to what you said, but do this stuff first, then we can look at the array.
i actually did try this before but it did not workout, this time i managed to make it work (with your help) and i got my player array. thanks
I'll update this post if i get stuck again (which I'm sure will happen again).
You've defined your vector to be a vector of Parent objects. This means that you are only storing base class objects in there, not the derived classes. Even though you're initialising the vector using derived class objects, the copies that are stored in the vector are just base class objects.
This is known as object slicing.
If you're looking to use polymorphism here, you need to store a vector of pointers to the objects.
In my opinion, you're still going about this wrong.
You don't need a different class for every single Pokemon.
You just need the Pokemon class, and each Pokemon has a name, life, strength defense, other stats, and a vector of attacks.
Likewise, you don't need a different class for every single move. Depending on the logic, you might want an Attack to derive from a Move, but you shouldn't need to make individual classes for every single move (Stomp, Tackle, Surf, etc.). You only need a class to define a category of classes.
e.g. a Move has-a type, strength, accuracy, side-effects.
The side-effects is where it's going to get complicated, and where you might want to use polymorphism.
#ifndef POKEMON_H
#define POKEMON_H
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
usingnamespace std;
int x,y,a,b,z,i,j,p_p,p_e,r_e,r_p,m,g;
struct attacks
{
string mv_name;
int power;
int pp;
int accuracy;
int side_effect;//1 for paralysis , 2 for burn
};
struct pokemon : public attacks
{
string name;
int life;
int stg;
int def;
attacks moves[2];
};
#include "pokemon.h"
int main() {
attacks ember;
ember.mv_name="Ember";
ember.power=80;
ember.pp=25;
ember.accuracy=90;
ember.side_effect = 2;
attacks thunderbolt;
thunderbolt.mv_name="Thunderbolt";
thunderbolt.power=80;
thunderbolt.pp=25;
thunderbolt.accuracy=90;
attacks quick_attack;
quick_attack.mv_name="Quick attack";
quick_attack.power=70;
quick_attack.pp=30;
quick_attack.accuracy=95;
attacks bubble;
bubble.mv_name="Bubble";
bubble.power=70;
bubble.pp=30;
bubble.accuracy=95;
attacks razor_leaf;
razor_leaf.mv_name="Razor Leaf";
razor_leaf.power=70;
razor_leaf.pp=30;
razor_leaf.accuracy=95;
attacks tail_whip;
tail_whip.mv_name="Tail Whip";
tail_whip.power=70;
tail_whip.pp=30;
tail_whip.accuracy=95;
attacks tackle;
tackle.mv_name="Tackle";
tackle.power=70;
tackle.pp=30;
tackle.accuracy=95;
tackle.side_effect = 1;
pokemon charmander;
charmander.name="Charmander";
charmander.life=500;
charmander.stg=5;
charmander.def=10;
charmander.moves[0]=ember;
charmander.moves[1]=tackle;
pokemon evee;
evee.name="Evee";
evee.life=500;
evee.stg=5;
evee.def=10;
evee.moves[0]=tail_whip;
evee.moves[1]=quick_attack;
pokemon pikachu;
pikachu.name="Pikachu";
pikachu.life=500;
pikachu.stg=5;
pikachu.def=10;
pikachu.moves[0]=thunderbolt;
pikachu.moves[1]=quick_attack;
pokemon bulbasaur;
bulbasaur.name="Bulbasaur";
bulbasaur.life=500;
bulbasaur.stg=5;
bulbasaur.def=10;
bulbasaur.moves[0]=razor_leaf;
bulbasaur.moves[1]=tackle;
pokemon squirtl;
squirtl.name="Squirtl";
squirtl.life=500;
squirtl.stg=5;
squirtl.def=10;
squirtl.moves[0]=bubble;
squirtl.moves[1]=tackle;
pokemon pidgey;
pidgey.name="Pidgey";
pidgey.life=500;
pidgey.stg=5;
pidgey.def=10;
pidgey.moves[0]=tackle;
pidgey.moves[1]=quick_attack;
vector<pokemon> player{{charmander, pikachu, squirtl}};
vector<pokemon> enemy{{bulbasaur, pidgey, evee}};
j= 0+rand()% 3;
cout << enemy[j].name << " has appeared\n\n";
cout << "press 1 to send out " << player[0].name << "\n";
cout << "press 2 to send out " << player[1].name << "\n";
cout << "press 3 to send out " << player[2].name << "\n";
cin >> z ;
if (z==1){i=0;}
elseif (z==2){i=1;}
elseif (z==3){i=2;};
do {
cout<<p_e;"\n";
cout << player[i].name << "'s turn\n";
cout << "press 1 to attack\n";
cout << "press 2 to use item\n";
cout << "press 3 to throw pokeball\n";
cin >> x ;
if (x==1){
if (p_e>-1){break;
cout << "press 1 to use " << player[i].moves[0].mv_name << "\n";
cout << "press 2 to use " << player[i].moves[1].mv_name << "\n";
cout << p_e;"\n";
cin >> y ;
if (y==1){m=0;}
elseif (y==2){m=1;};
if (y==1){
enemy[j].life = enemy[j].life - ((player[i].stg*player[i].moves[m].power)/enemy[j].def);
cout << enemy[j].name << "'s life :" << enemy[j].life << "\n";}
elseif (y==2){
enemy[j].life = enemy[j].life - ((player[i].stg*player[i].moves[m].power)/enemy[j].def);
cout << enemy[j].name << "'s life :" << enemy[j].life << "\n";}
if(player[i].moves[m].side_effect = 1){
g= 0+rand()% 100;
if (g>65){
p_p=0+rand()%2;}
elseif (player[i].moves[m].side_effect = 2){
g= 1+rand()% 100;
if (g>65){
r_p=0+rand()%2;}}
}}}
elseif (x==2){
cout << "press 1 to use heal\n";
cout << "press 2 to use cure paralysis\n";
cout << "press 3 to use heal burn\n";
cin >> a ;
if (a==1){
player[i].life = player[i].life + 60;
cout << player[i].name << "'s life :" << player[i].life << "\n";}
elseif (a==2){p_e=0;}
elseif (a==3){r_e=0;}}
elseif (x==3){
if (enemy[j].life >= 260){
b= 1+rand()% 30;
if (b<5){
cout << enemy[j].life << "caught\n";}
elseif (b>5){
cout << "missed\n";}
}
elseif (enemy[j].life < 260){
b= 1+rand()% 10;
if (b<5){
cout << enemy[j].life << "caught\n";}
elseif (b>=5){
cout << "missed\n";}
}
};
// PHASE 2
cout << enemy[j].name << "'s turn\n\n";
cout << "press 1 to attack\n";
cout << "press 2 to use item\n" ;
cin >> x ;
if (x==1){
if (p_p>-1){break;
cout << "press 1 to use " << enemy[j].moves[0].mv_name << "\n";
cout << "press 2 to use " << enemy[j].moves[1].mv_name << "\n";
cin >> y ;
if (y==1){
player[i].life = player[i].life - ((enemy[j].stg*enemy[j].moves[0].power)/player[i].def);
cout << player[i].name << "'s life :" << player[i].life << "\n";}
elseif (y==2){
player[i].life = player[i].life - ((enemy[j].stg*enemy[j].moves[1].power)/player[i].def);
cout << player[i].name << "'s life :" << player[i].life << "\n";}
if(player[i].moves[m].side_effect = 1){
g= 1+rand()% 100;
if (g>70){
p_e=0+rand()%2;}
elseif (player[i].moves[m].side_effect = 2){
g= 1+rand()% 100;
if (g>65){
r_e=0+rand()%2;}}
}}
elseif (x==2){
cout << "press 1 to use heal\n";
cout << "press 2 to use cure paralysis\n";
cout << "press 3 to use heal burn\n";
cin >> a ;
if (a==1){
enemy[j].life = enemy[j].life + 70;
cout << enemy[j].name << "'s life :" << enemy[j].life << "\n";}
elseif (a==2){
void cure_paralysis();}
elseif (a==3){
void cure_burn ();}}}}
while (player[i].life && enemy[j].life > 1);
}
i wanted some help with the paralysis and burn status (specially paralysis)
for paralysis when it's present in an attack theres a chance of paralysis the problem is i wanted to put it as if paralysis > 0 then (break) skip the enemy's attack turn but it just keeps skipping no matter what. any advice or better way to do it would be appreciated