- Home /
compare Attack and Defence attribute
Hi, A unit will have Defense rating per each of the 8 elements ( example shorten to 4 for simplicity). And an attack will be one of the element.
public class DefenceAtt{
public int PHY;
public int ENERGY;
public int HEAT;
public int FROST;
public DefenceAtt()
{
PHY = 0;
ENERGY = 0;
HEAT = 0;
FROST = 0;
}
}
public enum ELEMENT{ PHY, ENERGY, HEAT, FROST, LAST };
public class Attack{
public int power;
public ELEMENT element;
public DealDamage(pow, element) { /*DO Something here*/ }
}
Beside using SWITCH statement, is there any other convenient way to compare the Attacking Element to the related defence attribute?
THX in advance,
Comment
Answer by FL · May 05, 2013 at 01:26 PM
Use Builtin arrays. Instead of using four variable with each name, use public int[] defenceAtt = new int[4];
and create a enum/constant like
public enum ELEMENT()
{
PHY = 0;
ENERGY = 1;
HEAT = 2;
FROST = 3;
}
so
public DealDamage(pow, element) {
defenceAtt[element]-=pow;
}