我正在尝试让我的角色扮演游戏的战斗代码在被调用时激活

im trying to get my combat code for my rpg game to activate when called on

我正在寻找一种方法,以便当一个房间有 this.isCreatureInRoom = true; 来激活战斗代码时,有没有一种方法可以列出您可以在每个房间中战斗的不同生物 如果能帮我解决这个问题就好了

public Room(int x, int y, String description) {
    this.x = 0;
    this.y = -1;
    this.description = You Come Near The Exit Of The Cave To The South;
    this.isCreatureInRoom = true

public Combat() {
    Combat = 1;
    while (Combat == 1)
    {
        System.out.println("The Demon has attacked");
        HP = 20;
        HP2 = 15;
        System.out.println("Press A To Attack");
        try {
            Attack = input.readLine();
        } catch (IOException ioe) {
            System.out.println("input error");
        }
        if (Attack.equals("A")) {
            Random randomGenerator = new Random();
            Strike = randomGenerator.nextInt(10);
            Strike += 5;
            HP2 -= Strike;
            System.out.println("You Did " + Strike + " Damage");
            System.out.println("The Goblin Has " + HP2 + " Life Left");
            Strike2 = randomGenerator.nextInt(8);
            Strike2 += 5;
            HP -= Strike2;
            System.out.println("The Goblin Did " + Strike2 + " Damage");
            System.out.println("You Have " + HP + " Life Left");
            if (HP <= 0) {
                System.out.println("You Died. Game Over.");
                System.exit(0);
            } else if (HP2 <= 0) {
                Combat = 0;
                System.out.println("You Have Defeated The Demon! Conagradulations!");

            }
        }
    }
}

所以,你可以这样做,我认为它可行:

       public Combat()
 {
  if (isCreatureInRoom==true)
 {

   Combat = 1;

 }

 while (Combat ==1)
  {
         System.out.println("The Demon has attacked");
  .....
  }
  }
  }