Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pointer to object


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 15 March 2012 - 08:51 PM

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 ?

Sponsor:

#2 JustinDaniel   Members   -  Reputation: 137

Like
0Likes
Like

Posted 16 March 2012 - 12:02 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS