I'm trying to create a function that takes two player classes, compares which AttackElement they used, and is able to alter each class' variables based on which AttackElement has a better advantage.
I'm sure there's a much more logical way of doing this, but at the moment I'm stuck wondering if I could concatenate a string to call the correct variable. For example, if I am trying to access a variable in a player class called WaterStrength can I simply have a string that combines the word "Water" with "Strength" in order to call the variable? I know calling functions/variables doesn't normally work that way, but in this example I'm calling this iWantToCombineThis.
int baseDamage = 2;
class PlayerClass(){
int Health = 10;
int WaterStrength = 1;
int FireStrength = 1;
}
void AnalyzeRound(PlayerClass won, PlayerClass lost, string winningElement)
{
string iWantToCombineThis = winningElement + "Strength";
lost.Health -= baseDamage * won.iWantToCombineThis;
}
AnalyzeRound(Player1,Player2,"Water");
AnalyzeRound(Player2,Player1,"Fire");