我正在为我的计算机课制作Java
的游戏,我使用的是NetBeans
。它更像是一个选择你自己的冒险游戏。这是我的健康方法,如果他们选择了一个会对他们造成伤害的选项,我会调用它。
效果很好,它能按我想要的方式消除伤害。我遇到的一个问题是将if语句发送给gameover方法。它给了我下面的错误-
incompatible types
Required: boolean
Found: int
请帮我解决这个问题。
package sauvelostdog;
import java.awt.Toolkit;
import java.util.Scanner;
public class SauveLostDog {
//set starting health to 10
static int playerHealth = 10;
public static void health(int damageAmount) {
int damage;
//player taking 3 damage
if (damageAmount == 3) {
damage = 3;
playerHealth = playerHealth - damage;
System.out.println(playerHealth);
} else if (damageAmount == 4) {
//player taking 4 damage
damage = 4;
playerHealth = playerHealth - damage;
System.out.println(playerHealth);
} else if (damageAmount == 5) {
//player taking 5 damage
damage = 5;
playerHealth = playerHealth - damage;
System.out.println(playerHealth);
}
//this is what is giving me problems
if(playerHealth => 0){
gameover();
}
}
可变玩家生命值必须等于或小于零。当你的生命值大于等于0时,你实际上是在输出gameover();
。
if(playerHealth <= 0){
gameover();
}