对其他方法的所有调用都有效(例如player.isDead等)。
有问题的两种方法是:
我从Game类打电话给.fight开始战斗(带有怪物列表)。
public void fight() {
monster = monsterList.get(random.nextInt (monsterList.size()));
System.out.println("A" + " " + monster.getName() + " " + monster.getEnter());
//turn 0 = player
//turn 1 = monster
fight:
while(!player.isDead() && !monster.isDead()) {
while(turn == 0) {
String input = inputreader.getCommand();
if(input.contains ("run")) {
player.setGold(player.getGold()-50);
System.out.println("You throw 50 gold at the monster and escape in the confusion.");
break fight;
}
else if(input.contains ("attack")) {
break;
}
else if(input.contains ("help")) {
printHelp();
}
else if(input.contains ("inspect")) {
printDescription(monster);
}
}
gameAttack();
}
}
/**
* The fight between the monster and the player
*/
private void gameAttack() {
System.out.println("You attack! ");
int playerDamage = random.nextInt(21)+10;
monster.changeHealth(-playerDamage);
System.out.println(player.getName() + " hits " + monster.getName() + " for " + playerDamage + " damage! "
+ monster.getName() + " has " + monster.getHealth() + "/" + monster.getMaxHealth() + " hitpoints left! ");
if(monster.isDead()) {
System.out.println(player.getName() + " is victorious! " + "\n" + player.getName() + " looted the monster for "
+ monster.getGold() + " gold ");
player.setGold(player.getGold() + monster.getGold());
}
else{
turn = 1;
System.out.println("The monster attacks!");
int monsterDamage = random.nextInt(21)+20;
player.changeHealth(-monsterDamage);
System.out.println(monster.getName() + " hits " + player.getName() + " for " + monsterDamage + " damage! "
+ player.getName() + " has " + player.getHealth() + "/" + player.getMaxHealth() + " hitpoints left!");
}
if(player.isDead()) {
System.out.println(player.getName() + " has been slain by " + monster.getName() + ".\n" + "Game over, bro!");
}
else{
turn = 0;
}
}