Java 有人能帮我写代码吗?(爪哇)
我正在写一个小程序。Java 有人能帮我写代码吗?(爪哇),java,constructor,switch-statement,Java,Constructor,Switch Statement,我正在写一个小程序。 我是java编程的初学者。 下面是代码: 包装dnd public class Monster { static String name; static int level; static String rang; static String Class; static double[] Strength = {1, 1, 0}; static double[] Endurance = {1, 1, 0}; stat
我是java编程的初学者。
下面是代码:
包装dnd
public class Monster {
static String name;
static int level;
static String rang;
static String Class;
static double[] Strength = {1, 1, 0};
static double[] Endurance = {1, 1, 0};
static double[] Agility = {1, 1, 0};
static double[] Precision = {1, 1, 0};
static double[] Wisdom = {0, 1, 1};
static double[] Intelegence = {0, 1, 1};
public static void Monster(String nameC, int levelC, String classesC, int rangC){
name = nameC;
level = levelC;
switch(rangC){
case 1:
rang = "Civillian";
case 2:
rang = "Soldier";
case 3:
rang = "Veteran";
case 4:
rang = "Commander";
case 5:
rang = "Boss";
case 6:
rang = "Elite";
default:
rang = "Civillian";
}
Class = classesC;
switch(Class){
case "Warrior":
Strength[1] = 2;
Endurance[1] = 2;
Intelegence[1] = 0.5;
case "Archer":
Agility[1] = 2;
Precision[1] = 2;
Endurance[1] = 0.5;
case "Rouge":
Agility[1] = 2;
Intelegence[1] = 2;
Endurance[1] = 0.5;
case "Mage":
Wisdom[1] = 2;
Intelegence[1] = 2;
Strength[1] = 0.5;
case "Priest":
Wisdom[1] = 2;
Strength[1] = 0.5;
case "Druid":
Intelegence[1] = 2;
Agility[1] = 0.5;
}
}
public static void defaultStaringPoints(){
int StP;
int EnP;
int InP;
int AgP;
int PrP;
int WiP;
switch(Class){
case "Warrior":
//Strength
//Endurance
//-Intelegence
StP = (int) (Math.random() * 2);
EnP = (int) (Math.random() * (3-StP));
InP = (int) (Math.random() * (3-(StP+EnP)));
Strength[0] = Strength[0] + StP;
Endurance[0] = Endurance[0] + EnP;
Intelegence[0] = Intelegence[0] + InP;
case "Archer":
//Agility
//Precision
//-Endurance
AgP = (int) (Math.random() * 2);
PrP = (int) (Math.random() * (3-AgP));
EnP = (int) (Math.random() * (3-(AgP+PrP)));
Agility[0] = Agility[0] + AgP;
Precision[0] = Precision[0] + PrP;
Endurance[0] = Endurance[0] + EnP;
case "Rouge":
//Agility
//Intelegence
//-Endurance
AgP = (int) (Math.random() * 2);
InP = (int) (Math.random() * (3-AgP));
EnP = (int) (Math.random() * (3-(AgP+InP)));
Agility[0] = Agility[0] + AgP;
Intelegence[0] = Intelegence[0] + InP;
Endurance[0] = Endurance[0] + EnP;
case "Mage":
//Wisdom
//Intelegence
//-Strength
WiP = (int) (Math.random() * 2);
InP = (int) (Math.random() * (3-WiP));
StP = (int) (Math.random() * (3-(WiP+InP)));
Wisdom[0] = Wisdom[0] + WiP;
Intelegence[0] = Intelegence[0] + InP;
Strength[0] = Strength[0] + StP;
case "Priest":
//Wisdom
//-Strength
WiP = (int) (Math.random() * 3);
StP = (int) (Math.random() * (3-WiP));
Wisdom[0] = Wisdom[0] + WiP;
Strength[0] = Strength[0] + StP;
case "Druid":
//Intelegence
//-Agility
InP = (int) (Math.random() * 3);
AgP = (int) (Math.random() * (3-InP));
Intelegence[0] = Intelegence[0] + InP;
Agility[0] = Agility[0] + AgP;
}
}
}
然后我创建了一个新怪物,运行小妖精。怪物(“小妖精”,1,“胭脂”,2)
和
Goblin.defaultStaringPoints()
Arrays.toString(Goblin.wis智)
的输出应该是[0,1,1],但实际上它是[1,2,1],[2,2,1]甚至[3,2,1]。 我觉得,我只是在监督一些事情,
但我检查了10多次。
提前谢谢你 当您调用
defaultStartingPoints()
时,它会随机化统计信息,使WITH统计信息不再是[0,1,1]
在您的每个开关
语句中,您需要一个中断每个案例末尾的code>语句
。例如:
switch(rangC){
case 1:
rang = "Civillian";
break;
case 2:
rang = "Soldier";
break;
...
}
无中断代码>,执行将直接进入下一个案例
此外,在任何开关
语句中,您都没有案例
“妖精”
。您没有中断在你的switch()
案例末尾的code>语句。这并不重要,真的,但是OP永远不会在“Goblin”部分切换。