因此,我创建了一个用于获取游戏角色统计信息的代码,但它始终向我显示两个错误。我究竟做错了什么?任何帮助将不胜感激,因为我是这些命令的新手。预先感谢。
下面是一些代码:
public static void ShowStats(String Name, int Level, int Health, int ArrowCount, int Slots, int SlotsFilled, boolean hasJob, boolean hasEquipment, boolean hasMagicBook, String Jobs[], String JobLevels[], String Equipments[], String Crystals[], boolean isSoulBonded[], boolean isArrow[], int JobCount, int EquipmentCount)
{
int i;
System.out.println("Name: "+Name);
System.out.println("Level: "+Level);
System.out.println("Health: "+Health);
if(hasJob)
{
System.out.println("Jobs:");
for(i=0;i<JobCount;i++)
System.out.println(Jobs[i]+" job at level "+JobLevels[i]+".");
}
if(hasEquipment)
{
System.out.println("Equipments:");
for(i=0;i<EquipmentCount;i++)
{
if(isArrow[i])
{
System.out.println(ArrowCount+" "+Equipments[i]);
continue;
}
if(isSoulBonded[i])
{
System.out.println(Equipments[i]+" (Soul Bonded)");
continue;
}
System.out.println(Equipments[i]);
}
}
if(hasMagicBook)
{
System.out.println("Magic Book has "+SlotsFilled+"/"+Slots+" Crystals");
System.out.println("Crystals:");
for(i=0;i<SlotsFilled;i++)
System.out.println(Crystals[i]);
}
}
public static void GetStats(int c)
{
String n="";
int l=0,h=0,ac=0,s=0,sf=0,jc=0,ec=0;
boolean hj=false,he=false,mb=false;
if(c==0)
{
n="TestChar";
l=1;
h=52;
hj=true;
jc=3;
String j[]={"Fighter","Mage","Alchemist"};
String jl[]={"Neophyte","Neophyte","Neophyte"};
he=true;
ec=6;
String e[]={"Armor","Trousers","Boots","Dagger","Magic Book Lvl 1","Bag"};
boolean sb[]={false,false,false,false,false,false};
boolean a[]={false,false,false,false,false,false};
mb=true;
}
else if(c==1)
{
n="TestChar2";
l=5;
h=68;
hj=true;
jc=2;
String j[]={"Fighter","Mage"};
String jl[]={"Apprentice","Apprentice"};
he=true;
ec=6;
String e[]={"Armor","Leather Trousers","Leather Boots","Sword","Magic Book Lvl 2","Bag"};
boolean sb[]={true,false,false,false,false,false};
boolean a[]={false,false,false,false,false,false};
mb=true;
}
else
{
String j[]={"","",""};
String jl[]={"","",""};
String e[]={"","","","","","","",""};
String cf[] ={"","","","",""};
boolean sb[]={false,false,false,false,false,false,false,false};
boolean a[]={false,false,false,false,false,false,false,false};
}
ShowStats(n,l,h,ac,s,sf,hj,he,mb,j[],jl[],e[],c[],sb[],a[],jc,ec);
}
编译器显示ShowStats(n,l,h,ac,s,sf,hj,he,mb,j[],jl[],e[],c[],sb[],a[],jc,ec);
会产生错误,但是为什么呢?我真的很想得到我的帮助,对此我有点陌生,因此也欢迎提出任何解释。
答案 0 :(得分:0)
更改您的Array声明和赋值,例如String [] j,其他人也可以遵循相同的声明。
public static void GetStats(int c)
{
String n="";
int l=0,h=0,ac=0,s=0,sf=0,jc=0,ec=0;
boolean hj=false,he=false,mb=false;
String[] j;
if(c==0)
{
j[0]="Fighter";
j[1] ="Mage";
j[2]= "Alchemist";
}
else if(c==1)
{
j[0]="Fighter";
j[1] = "Mage";
} ...