Class question for RPG Game
Apr 12, 2009 at 5:45am UTC
Hi everyone, I'm making a simple RPG game and am using classes for my weapons. Here is a sample of my code:
1 2 3 4 5 6 7 8 9 10
class Sword
{
public :
string wName;
short wDMG;
};
Sword Falchion;
Falchion.wName= "Falchion" ;
Falchion.wDMG=12;
so that's gravy. When the player chooses their job class, it sets their base stats and their starting weapon.
My question is, how do I set the player's starting weapon to one of the sword objects?
Apr 12, 2009 at 6:04am UTC
Is player a class?
if so something like this should work: aPlayerObject.weapon = aSwordObject;
Apr 12, 2009 at 6:16am UTC
I don't have the player set as a class, though I could do that.
Assuming the above is included, is this how would the code look?
1 2 3 4 5 6 7 8 9 10
class Player
{
public :
short pATK,pDEF;
string pWPN; // Not sure about this
};
//player chooses job class
Player.WPN=Sword.Falchion; //??
Thanks for your help, I've got a lot to learn lol
Last edited on Apr 12, 2009 at 6:17am UTC
Apr 12, 2009 at 6:24am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Sword
{
//...
};
class Player
{
public :
Sword WPN;
//...
};
Sword Falchion;
Falchion.wName= "Falchion" ;//You may have a constructor
Falchion.wDMG=12;
Player player;//create an object of 'Player' class
player.WPN = Falchion;
Topic archived. No new replies allowed.