我想为整个程序设置一个'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.
}
}