我想为整个程序设置一个“if-then”语句。我想要:
if (health <= 0) {
JOptionPane.showMessageDialog(null, "You lost");
}
我无法让它正常工作。我正在尝试制作一个非常基本的基于文本的游戏,它不会不断检查运行状况。我不知道如何让它做到这一点,而不是每次发生损坏时都写它。
最佳答案
我不确定你是如何实现受到伤害的,但如果它是在一个方法中,你可以这样做:
private void takeDamage(double damage)
{
// Take the damage here. Then check the health.
if (health <= 0)
{
// Print the you lost message.
}
}
关于JAVA - 如果-那么需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950674/