当健康等于0时,我如何调用我的游戏方法?

时间:2013-01-20 07:20:57

标签: if-statement methods global-variables health-monitoring method-call

我正在为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();

     }
 }

1 个答案:

答案 0 :(得分:1)

可变的球员健康必须等于或小于零。当您的健康状况大于或等于零时,您实际上是在输出gameover();

if(playerHealth <= 0){
    gameover();
}