我试图让我的RPG游戏的战斗代码在被召唤时激活

时间:2015-01-23 02:50:37

标签: java while-loop this

我正在寻找一种方法来实现这一点,当一个房间有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!");

            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

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

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

   Combat = 1;

 }

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