This code feels long and clunky to me. How can I make it shorter, if possible?
I am writing for a libGDX game, and I need a skill algorithm. I want it so once the player picks up something (which I already have checked for) I set a, b or c to a certain SkillType, the enum down below. Then, I want to get the value of the specific SkillType, by using the enum's methods to get cooldown and cost.
public SkillType[] skills;
public SkillType a, b, c;
public int acost, bcost, ccost;
public int acooldown, bcooldown, ccooldown;
skills = new SkillType[3];
skills[0] = a; skills[1] = b; skills[2] = c;
acost = a.getCost(); bcost = b.getCost(); ccost = c.getCost();
acooldown = a.getCooldown(); bcooldown = b.getCooldown(); ccooldown = c.getCooldown();
public SkillType getSkill(int index) { return skills[index]; }
public void setSkill(int index, SkillType skill) { skills[index] = skill; }
This code declares the enum used above. It has all the skills that I want to use. It declares, inside the SkillType
, its cost and cooldown. I do not want to change these values, and that's why I don't have setters.
public static enum SkillType {
ROAR(1,3),
DUST_CLOAK(2,10),
THORN_CLOAK(2,10),
SPARK(2,5),
FLUTTER(0,0),
EMBER(2,2),
GLOW(0,0),
SCRATCH(0,0),
BITE(0,0);
int cost;
int cooldown;
SkillType(int cost, int cooldown) {
this.cost = cost;
this.cooldown = cooldown;
}
public int getCooldown() { return cooldown; }
public int getCost() { return cost; }
}
EDIT:
I have updated the enum class to include more items.
public class SkillData {
public SkillType[] skills;
public static final int MAX_SKILLS = 3;
public static final int SLOT_PRIMARY = 0;
public static final int SLOT_SECONDARY = 1;
public static final int SLOT_SECONDARY_TWO = 2;
public static enum SkillType {
ROAR(1,3),
DUST_CLOAK(2,10),
THORN_CLOAK(2,10),
SPARK(2,5),
FLUTTER(0,0),
EMBER(2,2),
GLOW(0,0),
SCRATCH(0,0),
BITE(0,0);
int cost;
int cooldown;
SkillType(int cost, int cooldown) {
this.cost = cost;
this.cooldown = cooldown;
}
public int getCooldown() { return cooldown; }
public int getCost() { return cost; }
}
public SkillData() {
skills = new SkillType[MAX_SKILLS];
}
public int getCost(int index) { return skills[index].getCost(); }
public int getCooldown(int index) { return skills[index].getCost(); }
public void setSkill(int index, SkillType skill) { skills[index] = skill; }
public SkillType getSkill(int index) { return skills[index]; }
public SkillType[] getSkills() { return skills; }
}
SkillType
class from the first code block... can you kindly explain/edit the first code block to indicate if that's in another class, how they are used, etc.? Thanks! :) \$\endgroup\$ – h.j.k. Jun 24 '15 at 1:29