Of course, variable naming is completely up to you, but I just wanted to use the most descriptive name possible so that I could get my idea across as easily as possible
Code:
//MyDefinitions.h
//This next line will set a cap on the number of Skills and Spells you,
//as a programmer, will be able to incorporate into your game. You'll
//have to adjust this number each time you add more Skills or Spells,
//otherwise your program will crash. Should this number be BIGGER than
//your actual number, then it won't crash, but you will be wasting memory
//This line would not be enough
//#define NUMBER_OF_SKILLS_AND_SPELLS 1
//This line would waste space
//#define NUMBER_OF_SKILLS_AND_SPELLS 100
//This line is just right
#define NUMBER_OF_SKILLS_AND_SPELLS 5
//Now, we will have enough room for the following Skills/Spells
//It's important that the numbering goes from 0 to (NUMBER_OF_SKILLS_AND_SPELLS - 1)
#define DAGGER_SKILL 0
#define CLUB_SKILL 1
#define SHIELD_SKILL 2
#define BARDIC_LEARNING_SPELL 3
#define MASS_HEAL 4
//Note:
//With this method, the most setup will come from
//ensuring this file is setup properly. Following that, the
//rest of your functions will remain small and take up very little
//space
Now that we have THAT setup, our Class is about to look much smaller
Code:
//cPlayer.h
#ifndef CPLAYER_H
#define CPLAYER_H
#include "MyDefinitions.h"
class cPlayer
{
public:
cPlayer(void); //Our Constructor
void SetValue(int SkillOrSpellID, int Value); //Sets the current value
int GetValue(int SkillOrSpellID); //Returns the current value
private:
int SkillAndSpellValues[NUMBER_OF_SKILLS_AND_SPELLS];
//Now you hopefully see why the number must be defined properly
//in MyDefinitions.h
//And THAT'S IT for our class
};
#endif
Now, we have an array that will hold all of our skill and spell values. So, on to the actual functions:
Code:
//cPlayer.cpp
#include "cPlayer.h"
cPlayer::cPlayer(void)
{
int X;
for(X = 0; X < NUMBER_OF_SKILLS_AND_SPELLS; X++)
{
SkillAndSpellValues[X] = 0;
}
//Now all our values have been initialized to 0
}
void cPlayer::SetValue(int SkillOrSpellID, int Value)
{
SkillAndSpellValues[SkillOrSpellID] = Value;
}
int cPlayer::GetValue(int SkillOrSpellID)
{
return SkillAndSpellValues[SkillOrSpellID];
}
And that's it. Now, to use our class:
Code:
//Main.cpp
#include <stdio.h> //Again, for C functions
#include "cPlayer.h"
int main(void)
{
cPlayer MyPlayer;
printf("Dagger Skill: %d", MyPlayer.GetValue(DAGGER_SKILL));
printf("\n"); //Prints a New Line
MyPlayer.SetValue(DAGGER_SKILL, 50);
printf("Dagger Skill: %d", MyPlayer.GetValue(DAGGER_SKILL));
return 0;
}
And the expected output would be:
Dagger Skill: 0
Dagger Skill: 50
As you can see, aside from a bigger Definitions file, the rest is relatively compact and clean. Again, this is just another idea, I'm sure there are many more, and better, ways out there. But this is probably the best one that I could think of at the moment.