好的家伙,请耐心等我,我需要添加一个健康栏,但在添加健康栏之前我需要让它正常工作。
问题: 当我运行它并且它滚动它将落在一个数字并选择一个命中,当它确定它通过多种类型的命中而不仅仅是一个命中时。如果愿意的话,尝试运行它。希望评论有所帮助。
我尝试了什么: 我已经尝试过对所有事情进行精细梳理,但经过大约2个小时的调整后无法找到我已经转向此处的解决方案....
进口: import javax.swing.JOptionPane; import java.util.Random;
声明值:
int life = 100; //Your life
int life2 = 100; //Enemy life
Random chance = new Random();
while (life >= 0 && life2 >= 0){ //loop
int hitchance = chance.nextInt(100)+1;
System.out.println(hitchance); //Your roll
if (hitchance <= 20 ){//Miss
JOptionPane.showMessageDialog(null, "You have missed your opponent like a fool.\nYour Opponent has "+life2+" health remaining.");
}
if (hitchance >= 21 && hitchance <= 34){//Wiff
int Wiff = chance.nextInt(10)+1;
life = life-Wiff;
JOptionPane.showMessageDialog(null, "You have stubbed your toe. Idiot.\nYou have "+life+" health remaining." +Wiff);
}
if (hitchance >= 35 && hitchance <= 74){//Regular Hit
int regHit = chance.nextInt(20)+1;
life2 = life2-regHit;
JOptionPane.showMessageDialog(null, "You have hit your opponent for "+regHit+" damage!\nThey have "+life2+" health remaining.");
}
if (hitchance >= 75 && hitchance <= 90){//CritHit
int critHit = chance.nextInt(40)+1;
life2 = life2-critHit;
JOptionPane.showMessageDialog(null, "You have dealt critical damage! "+critHit+"\nThey have "+life2+" health reamining.");
}
if (hitchance >= 91 && hitchance <= 100) {//Fatality.
JOptionPane.showMessageDialog(null, "Fatality!\nYou stabbed your opponent in the foot,\ndrug your knife throught"
+ "his belly,\nand impaled his head on your knife!");
System.exit(0);
}
int hitchance2 = chance.nextInt(100)+1;
System.out.println(hitchance2); //Enemy roll
if (hitchance2 <= 20 ){//Miss
JOptionPane.showMessageDialog(null, "Your opponent has missed you.\nYou have "+life+" health remaining.");
}
if (hitchance2 >= 21 && hitchance <= 34){//Wiff
int Wiff = chance.nextInt(10)+1;
life2 = life2-Wiff;
JOptionPane.showMessageDialog(null, "Your enemy has stubbed his toe. Idiot.\nThey have "+life2+" health remaining." +Wiff+" Damage dealt.");
}
if (hitchance2 >= 35 && hitchance <= 74){//Regular Hit
int regHit = chance.nextInt(20)+1;
life = life-regHit;
JOptionPane.showMessageDialog(null, "Your opponent has hit you for "+regHit+" damage!\nYou have "+life+" health remaining.");
}
if (hitchance2 >= 75 && hitchance <= 90){//CritHit
int critHit = chance.nextInt(40)+1;
life = life-critHit;
JOptionPane.showMessageDialog(null, "Your opponent has dealt critical damage! "+critHit+"\nYou have "+life+" health reamining.");
}
if (hitchance2 >= 91 && hitchance2 <= 100) {//Fatality.
JOptionPane.showMessageDialog(null, "Fatality!\nYour opponent stabbed you in the foot,\ndrug their knife through"
+ "your belly,\nand impaled your head on his knife!");
System.exit(0);
}
}
}
}
答案 0 :(得分:0)
代码中有几个条件似乎不正确,例如。
hitchance2 >= 21 && hitchance <= 34
这解释了为什么你可能会随机点击。