- 180
- Posts
- 13
- Years
- Seen Aug 12, 2023
I asked a question regarding tips on a pokemon engine about a year ago, and I've taken a pretty long vacation from learning c++ programming. I've since reread the topic and can now understand every suggestion given to me, but... Since I'm just getting back into it, and consider myself a n00b programmer, I was hoping you guys could help me clear up a few concepts. I've barely started coding, rather just practicing each object oriented method I can think of that will go into the application before I actually start the programming for the real thing.
1. Is there a way where one class can just read another class's object without invoking the outside class's constructor?
Here's some of the code so far to show what I've done.
I'm pretty sure there's some ugliness in that code, but yeah.
2. I remember a while ago that someone said making a subclass for each pokemon is not a great idea. So instead, each pokemon will be an instance of the pokemon class (and makes more sense now that I think about it). The pokemon class constructor will initialize the base stats and name of the pokemon. ( Pokemon Bulbasaur("Bulbasaur", 45, 49, 49, 45, 65, 65) ). Is this the correct way of going about it?
1. Is there a way where one class can just read another class's object without invoking the outside class's constructor?
Here's some of the code so far to show what I've done.
Spoiler:
Code:
typedef shared_ptr<Pokemon> Pokemon_ptr; // Define type of smart pointer to class
class Player
{
public:
vector<Pokemon_ptr> Party; // Make a vector of smart pointers that point to class objects
Player();
Player(const Player& p);
void AddPokemon();
};
// ............
Player::Player()
{
Party.reserve(6);
cout << "Welcome!" << endl << endl;
} // I'm pretty sure this isn't exactly the right use of a constructor, but this is just for testing purposes.
void Player::AddPokemon()
{
Party.push_back(Pokemon_ptr (new Pokemon("Bulbasaur", 45, 49, 49, 45, 65, 65))); // vector.push_back(smart_pointer_type (new object(constructor init args)))
cout << Party[0]->m_name << " was added!" << endl << endl;
}
// .............
class Battle
{
public:
int battle_hp;
int battle_atk;
int battle_def;
int battle_specatk;
int battle_specdef;
int battle_speed;
Player p;
Battle(const Player &p);
};
Battle::Battle(const Player &p)
{
cout << "Calling for base HP of pokemon in the Player class - " << p.Party[0]->m_base_hp << endl;
p.Party[0]->m_base_hp = 51;
cout << "Calling for base HP of pokemon in the Player class - " << p.Party[0]->m_base_hp << endl;
}
//main
int main()
{
Player aPlayer;
aPlayer.AddPokemon();
Battle Startbattle(aPlayer);
cout << "Base HP of pokemon in the Player class in main after battle constructor - " << aPlayer.Party[0]->m_base_hp;
return 0;
}
// I know it isn't great, and this won't be part of the final code. I plan on separating classes into separate files. Like I said, it's practice. If there's anything you can point out of what a better method would be, please say so.
I'm pretty sure there's some ugliness in that code, but yeah.
2. I remember a while ago that someone said making a subclass for each pokemon is not a great idea. So instead, each pokemon will be an instance of the pokemon class (and makes more sense now that I think about it). The pokemon class constructor will initialize the base stats and name of the pokemon. ( Pokemon Bulbasaur("Bulbasaur", 45, 49, 49, 45, 65, 65) ). Is this the correct way of going about it?