【发布时间】:2016-03-20 22:47:59
【问题描述】:
我目前正在编写一个游戏的代码,其中一个敌人(一只蝙蝠)的生命值应该会下降,但它不起作用。
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。
谢谢, 极光
【问题讨论】:
-
或许可以提供一些关于什么不起作用的信息。您是否尝试过在调试器中查看发生了什么?
标签: java class variables methods