如何使用调用方法修改变量?

时间:2018-03-12 19:57:03

标签: java variables methods global-variables netbeans-8

我不是很擅长修改变量,所以我想问一下如何在循环中修改enemyhp以便我可以继续攻击直到enemyhp< = 0。自方法"攻击"在另一个班级,我只是继续调用方法,直到我实现敌人< = 0因此杀死敌人,攻击敌人后应该下降;从20-> 18-> 16 ......但是之后的攻击只是停留在18

    public static void startmenu()throws IOException{
    BufferedReader br = new BufferedReader(new
    InputStreamReader(System.in));
        Story.IntroStory();
        br.readLine();
        System.out.println("=======BARBIE THE BARBARIAN!=======");
        System.out.println("Main Menu\n"
                + "[1]Start Game\n"
                + "[2]Exit\n");
        System.out.print("Enter choice:");
        int choice= Integer.parseInt(br.readLine());
        int enemyhp=0+Enemy.enemyHP[0];
        int playerDMG=0+Player.playerDMG;
        String enemyN= Enemy.enemyN[0];
        if(choice==1){
            System.out.println("Welcome! ");
            Story.first();
            br.readLine();
            Story.adanger();
            br.readLine();
            Fight.encounter1();
            while(enemyhp>0){
            Fight.battlemenu();
            int move= Integer.parseInt(br.readLine());
            if (move==1){
                Fight.attack(enemyN,enemyhp,playerDMG);
            }
        }}
public static int attack(String enemyN,int enemyhp,int playerDMG){
int hpleft=enemyhp-playerDMG;
enemyhp=enemyhp-playerDMG;
System.out.println("You attacked "+enemyN+" and caused "+playerDMG+" Damage"
        + "\nEnemy HP: "+ hpleft);
        int playerDamage = playerDMG;
        int DMGtaken = playerDamage;
        enemyhp -= Math.abs(DMGtaken);
        if(enemyhp <= 0){
            System.out.println(enemyN+" Died.");
            System.out.println("Victory");
            System.out.println("Remaining HP: "+Player.hp);
            System.out.println("[Press Enter to continue]");
        }return enemyhp;

      public class Enemy {
public static String[] enemyWPN={"Iron Tusks","Steel Knuckles","Blade of the Ruined King"};
public static String[] enemyN={"Iron Leathered Boar","Mighty Steel Minotaur","KING"};
public static int[] enemyDMG={2,4,6};
public static int[] enemyHP={20,26,35};

}

0 个答案:

没有答案