0
我目前正在編寫一個遊戲,其中一個敵人(蝙蝠)應該使其健康下降但不起作用。嘗試更改變量的Java方法無法正常工作
class BatTest{
public static void main(String args[]) {
String input = "";
boolean exit = false;
Bat bat1 = new Bat();
Inventory MainInv = new Inventory();
MainInv.smallknife = true;
System.out.println("A bat has appeared!");
System.out.println("Health: " + bat1.health + " Attack Strength: " + bat1.damage);
do{
System.out.println("Health: " + bat1.health + " Attack Strength: " + bat1.damage);
System.out.print("What would you like to do: ");
input = Keyboard.readString();
if (input.equalsIgnoreCase("Attack")) {
Abilities.smallknifeMA(bat1.health);
System.out.println(bat1.health);
}
else if (input.equalsIgnoreCase("exit")) {
exit = true;
}
}while(!exit);
}
}
//enemyH denotes the health of the enemy
class Abilities {
static double smallknifeMA(double enemyH) {
enemyH = enemyH - 2.0;
return enemyH;
}
}
class Inventory {
boolean smallknife;
boolean startlockerkey;
}
我實在無法理解爲什麼smallknifeMA不降低可變bat1.health。
感謝, 極光
也許提供一些有關什麼不工作的信息。你有沒有嘗試在調試器中查看發生了什麼? – dman2306