我在BlueJ编程,我对这些字段有疑问。问题是只有当我关闭终端窗口时,字段值才会实时更新。我想要做的是创造怪物和玩家互相争斗的地方,但当他们相互攻击时,健康等野外值不会降低。
这部分代码来自Player类:
public int damageMonster(Monsters monster) {
int damage = minDamage + randomGenerator.nextInt(maxDamage-minDamage);
monster.changeHealth(-damage);
return damage;
}
这部分代码来自Battleground类:
public void start() {
boolean finished = false;
printWelcome();
while(!finished) {
String input = reader.getInput().trim().toLowerCase();
if(input.startsWith("run")) {
finished = true;
}
if(input.startsWith("attack")) {
System.out.println(player1.getName()+ " and " + randomBeast.getType()+ " enter the arena");
System.out.println(player1.getName()+ " deals " + player1.damageMonster(randomBeast) + " damage.");
System.out.println(randomBeast.getType() + " deals " + randomBeast.damagePlayer(player1) + " damage");
} else if(input.startsWith("run")) {
System.out.println(player1.getName() + " left the match and lost 50 gold");
//player1.getGold()= player1.getGold()-50;
} else {
System.out.println("You need to insert one of the commands mentioned above");
}
}
}