首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rng那种坏了吗?

Rng那种坏了吗?
EN

Stack Overflow用户
提问于 2015-12-22 02:08:51
回答 1查看 31关注 0票数 0

好的,伙计们,请原谅我,我需要添加一个健康栏,但是在我添加一个健康栏之前,我需要让它正常工作。

问题是:当我运行它并滚动它时,它将落在一个数字上,并选择一个命中,当它确定命中时,它会通过多种类型的命中,而不仅仅是一个。试试看如果你愿意的话。希望这些评论能有所帮助。

我试过的是:我试过仔细梳理每一件事,但经过大约两个小时的调整,找不到解决办法,我在这里求助.

进口:进口javax.swing.JOptionPane;进口java.util.Random;

申报价值:

代码语言:javascript
复制
    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);

}
}
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-22 02:19:14

代码中有几个似乎不正确的条件。

代码语言:javascript
复制
hitchance2 >= 21 && hitchance <= 34

这就解释了为什么你可能会有随机点击。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34407433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档