Hi, I'm working on creating my first game to sharpen my programing skills and as a great learning experience for programming in general.
I'm using private ints for the stats and was working on get and set methods for retrieving them and changing them and I was wondering if anyone could tell me how to go about this without having to create a if statement for each variable in the class (since there are many)
Condensed version of code for example:
class Character
{
private int str;
private int HP;
private int spd;
public int getStat(String stat)
{
//here is where I want to return the value of the
//variable above with the matching name to stat
}
public int setStat(String stat, int x)
{
//here is where I want to change the variable above
//with the matching name of stat to x
}
}
How would I go about it?