对于我的程序,我有大量的公共静态 int,它主要是一个可读性的东西,所以我可以做一些事情,比如SkillsArray[Archery] = 25
一眼就能看到“射箭技能”的值/级别/等级为 25,而不是试图弄清楚应该是什么SkillsArray[7] = 25
意思。
它基本上是命名要在关系数据库结构中使用的唯一 ID,但如果我想打印这些名称,我会构建一个函数,该函数接受一个 int 参数,该参数读取一个巨大的 if/else 树以吐出一个名为“射箭”或“烹饪”之类的。
我想用简单的东西替换所有这些功能
String printStaticName() {
return this.getClass().getName();
}
它可以读取附加到它的原语并获得它的名称,但 Eclipse 告诉我我不能对原语类型执行这些操作。想法?
我目前如何使用我拥有的系统的一个例子。
//races
public static final int Chosen = 0;
public static final int Native = 1;
public static final int High_Elf = 2;
public static final int Wood_Elf = 3;
public static final int Gremlin = 4;
public static final int Goblin = 5;
public static final int Hobgoblin = 6;
....
String getRaceNameString(int r){
String temp = "No Race Set";
if (r == Chosen){temp = "Chosen";};
if (r == Native){temp = "Native";};
if (r == High_Elf){temp = "High Elf";};
if (r == Wood_Elf){temp = "Wood Elf";};
if (r == Gremlin){temp = "Gremlin";};
if (r == Goblin){temp = "Goblin";};
if (r == Hobgoblin){temp = "Hobgoblin";};
return temp;
}//close getRaceNameString
int getRaceIDFromString(String r){
int result = 0;
if (r == "Chosen"){result = Chosen;};
if (r == "Native"){result = Native;};
if (r == "High Elf"){result = High_Elf;};
if (r == "Wood Elf"){result = Wood_Elf;};
if (r == "Gremlin"){result = Gremlin;};
if (r == "Goblin"){result = Goblin;};
if (r == "Hobgoblin"){result = Hobgoblin;};
return result;
}//close getraceIDFromString()
class Race extends WoSCharacter {
private int raceID = Chosen;
private double purity = 1;
private String active_headshot = "headshot.jpg";
private String active_fullbody = "TemplateforPortrait.png";
private String Description;
private double minHeight;
private double maxHeight;
private int AttributeMods[] = new int[9];
private double lifespan;
private boolean isModRace = false;
void setRace(int RName, long pure, int gender){
purity = pure;
raceID = RName;
switch (raceID){
//region case
case Chosen:
AttributeMods[STR] = 5;
AttributeMods[DEX] = 5;
AttributeMods[CON] = 5;
AttributeMods[CHA] = 5;
AttributeMods[PER] = 5;
AttributeMods[WIL] = 5;
AttributeMods[INT] = 5;
AttributeMods[INS] = 5;
AttributeMods[WIS] = 5;
active_headshot = "headshot.jpg";
Description = "The race of man are the sole survivors of the Mage Wars that took destroyed magic and everything but the animal races and humanity. Now they are facing their own extinction as the Black Plague washes over the world, crossing continents and destroying entire family lines. Some of mankind have developed an immunity, being christened 'the chosen' but this this comes at cost as they are further divorced from the just now returning powers of magic.";
minHeight = 150;
maxHeight = 170;
lifespan = 50;
if (gender == MALE){
active_headshot = "male_headshot.jpg";
active_fullbody = "TemplateforPortrait.png";
minHeight = 162;
maxHeight = 190;
lifespan = 49;
}else if (gender == FEMALE){
active_headshot = "Fem_headshot.jpg";
active_fullbody = "Fantasy_Landscape_01.jpg";
minHeight = 150;
maxHeight = 170;
lifespan = 43;
}//gender headshot switch
break;
//endregion case
case Native:
AttributeMods[STR] = 5;
AttributeMods[DEX] = 5;
AttributeMods[CON] = 5;
AttributeMods[CHA] = 5;
AttributeMods[PER] = 5;
AttributeMods[WIL] = 5;
AttributeMods[INT] = 5;
AttributeMods[INS] = 5;
AttributeMods[WIS] = 5;
active_headshot = "headshot.jpg";
Description = "The race of man are the sole survivors of the Mage Wars that took destroyed magic and everything but the animal races and humanity. Now they are facing their own extinction as the Black Plague washes over the world, crossing continents and destroying entire family lines. Some of mankind have developed an immunity, being christened 'the chosen' but this this comes at cost as they are further divorced from the just now returning powers of magic.";
minHeight = 150;
maxHeight = 170;
lifespan = 49;
if (gender == MALE){
active_headshot = "male_headshot.jpg";
active_fullbody = "TemplateforPortrait.png";
minHeight = 162;
maxHeight = 190;
lifespan = 49;
}else if (gender == FEMALE){
active_headshot = "Fem_headshot.jpg";
active_fullbody = "TemplateforPortrait.png";
minHeight = 150;
maxHeight = 170;
lifespan = 43;
}//gender headshot switch
break;
}
}