Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pointer to object

Started by Assassin7257 Mar 16, 2012 at 2:51 AM 0 replies 1.1k views
Original Post
Assassin7257
Assassin7257
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 ?
Justindano
Justindano
I'm a bit confused on what you said, But as far as i read.

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;
}


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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.