Class problems

Started by
12 comments, last by Rasmadrak 20 years, 1 month ago
Ok.. =)

but i want all items to be "things", since then I could use


for (int i=0; i < 10000;i++)
Things->Draw();<br><br><br>I found out that I can use following code instead;<br><br>void weapon::GiveWeapon(int nr)<br>{<br>WeaponStrength = WeaponSystems[nr]->WeaponStrength;<br>WeaponRange = WeaponSystems[nr]->WeaponRange;<br>WeaponReloadTime = WeaponSystems[nr]->WeaponReloadTime;<br>WeaponTimeToReload = WeaponSystems[nr]->WeaponTimeToReload;<br>WeaponType = WeaponSystems[nr]->WeaponType;<br>WeaponMaxAmmo = WeaponSystems[nr]->WeaponMaxAmmo;<br>WeaponCurrentAmmo = WeaponSystems[nr]->WeaponCurrentAmmo;<br>NameWeapon = WeaponSystems[nr]->NameWeapon;<br>};<br><br><br>this works, but is more awkward than the version I had in mind…. if I add a variable to the weapon class, I have to add the variable in the "GiveWeapon()" too…. well well, not a big problem.. just awkward.. =)<br><br><br>thanks for your time anyway!! <br><br><img src="smile.gif" width=15 height=15 align=middle><br> <br><br><SPAN CLASS=editedby>[edited by - Rasmadrak on March 20, 2004 1:03:25 PM]</SPAN>
"Game Maker For Life, probably never professional thou." =)
Advertisement
You can still do
for (int i=0; i < 10000;i++)Things[ i ]->Draw();


With this method...

Look more into class inheritance and you should understand why Weapon and Armor should inherit from Thing rather than the other way around.
Half the people you know are below average.Trogdor the Burninator
Kaezins right, your current system has ''thing'' as a subclass of ''weapon'', not the other way round. Youd definitely want it to be:

class thing
{
// common members to all classes
// + common virtual functions (eg:virtual void Draw())
}

class weapon: public thing
{
// implementation
}
Ok, =)

I think I got this now...
Right now I got it like this...

class physics
{
public:
//lots of physics stuff
private:
};

class things :
public physics
{

weapon *Weapon;

};



will it be possible to change the weapon by doing this:

Things->Weapon = ListOfWeapons[ 5 ]; <br><br>? <br><br>I''m not at home right now, so I cant check it myself… <br>Eager to know! :D<br><br>thanx for your help! I''m a total newb to classes, especially with inheritance and such… I''ve been using structs before.. =)<br><br>/Robert <br><br>"Game Maker For Life, probably never professional thou." =)
"Game Maker For Life, probably never professional thou." =)

This topic is closed to new replies.

Advertisement