Basically I am trying to figure out which control structures to use when structuring the following data:
Player data. This is initially determined by two entities: Player's Race and Player's Class. When selecting a Race, varying pre-determined base values will be set to determine things like HP, MP, damage, etc. Selecting a Class will set your character's level to 1. Each Class and each Race will separately add a varying amount of these stats ON TOP OF the base values for every level-up that the player gains. For example, a Human would start off with 40 max health and gain +4 max health per level up. If this Human is a fighter, he would gain an additional +4 max health per level up. So basically at level 1, a Human Fighter would have 48 max health. Here's the equation for that:
player max hp = 40 base hp + (4 human hp + 4 fighter hp)
Simple algebra. I avoided using
code
simply to avoid syntax highlighting for the equation itself.
Now I'll share some code so hopefully you can get a better grasp of what I'm trying to do. I will ask questions via //comments, as well as asking additional questions after the following code block:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
struct player //BASIC (and incomplete) PLAYER CHARACTER STAT RUNDOWN
{
int lvl; //player's current level. Should this be a constant?
int lvlexp; //experience points needed for player to level up. Constant?
int currentexp; //player's current experience points. Constant?
int maxhp; //player's maximum hit points
int currenthp; //player's current hit points
int maxmp; //player's maximum magic points
int currentmp; //player's current magic points
int gold; //player's gold. Should this also be a constant?
}
human, dwarf, imp, fighter, rogue, mage; /*Should I make separate structures for Races and Classes?*/
void ifhuman() //BASE STATS FOR HUMAN
{
std::string race= "Human";
human.maxhp=40;
human.currenthp=40;
human.maxmp=25;
human.currentmp=25;
human.gold=12;
}
|
Now the reason I ask if these should be constants is because I can't figure out how to get this code to compile properly with the following code included:
1 2 3 4 5 6 7 8 9 10 11
|
void lvlfighter()
{
std::string clas = "Fighter";
fighter.lvl = player::lvl+1;
fighter.lvlexp = player::lvlexp+200;
fighter.maxhp = player::maxhp+7;
fighter.currenthp = player::currenthp+7;
fighter.maxmp = player::maxmp+1;
fighter.currentmp = player::currentmp+1;
fighter.gold = player::gold+7;
}
|
Because of this one glaring error:
error C2597: illegal reference to non-static members:
player::lvl, player::lvlexp, etc.
How do I arrange my
struct
syntax so that the player's stats can be manipulated via outside (public) functions using only 1 reference in my formulas? Static class variables? Friendship?
I tried dicking around with it in VS 2010 after reading
http://www.cplusplus.com/doc/tutorial/classes2/
If anybody could help me, that would be great. I hope my question is straightforward enough. Thanks in advance for any help, it is greatly appreciated.
-Adam