我正在为我的计算机课制作游戏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();
}
}