• Advertisement
Sign in to follow this  

Pointer to object

This topic is 2134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I'm creating a game that has two classes. The player class and enemy class. The player makes a choice, and the enemy has to make a choice as based on the players. For example, in Pokemon you choose your starting pokemon, if you pick a Cyndaquil or Charmander, your rival will automatically pick a Squirtable or Totodile. How would I do that ?

Share this post


Link to post
Share on other sites
Advertisement
I'm a bit confused on what you said, But as far as i read.
[code]
class Player
{
private:
bool charmander;
public:
Player();
void SetPokemon();
bool getChoice();
};

Player::Player()
{
charmander = false;
}

void Player::SetPokemon()
{
if( //condtions met here.. )
{
charmander = true;
}
}

bool Player::getChoice()
{
return charmander;
}

class Enemy
{
public:
void SetPokemon( bool choice );
};

int main()
{
Player thisPlayer;
Enemy thisEnemy;
thisEnemy.SetPokemon(thisPlayer.getChoice());
//Do all the stuff;
}
[/code]

Or you can simply use Inheritance to just directly acces the boolean choice and update everything in the enemy class. Its all upto you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement