如何设置范围attack@damage 对于在主方法中使用类(java)声明的每个怪物

kulphzqa  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(210)

我正在用java做一个rpg游戏。我是java初学者
我有16种不同类型的怪物,可以提供不同的生命值,攻击,金币掉落,经验掉落。所以怪物类在战斗系统项目中。
我如何为班上的每个怪物设置不同的统计数据?例如,我想为knotty设置:他的攻击范围是1-5 atk

package battlesystem;

public class Monsters {

    private int lvl_monster;
    private String name_monster;
    private int hp_monster;
    private int atk_monster;
    private int def_monster;
    private int ag_monster;
    private int g_monster;
    private int exp_monster;

    //constructors

    public Monsters (int lvl_monster, String name_monster, int hp_monster, int atk_monster, int def_monster, int ag_monster, int g_monster, int exp_monster) {
        this.lvl_monster = lvl_monster;
        this.name_monster = name_monster;
        this.hp_monster = hp_monster;
        this.atk_monster = atk_monster;
        this.def_monster = def_monster;
        this.ag_monster = ag_monster;
        this.g_monster = g_monster;
        this.exp_monster = exp_monster;
    }

    public void setLvl_monster(int lvl_monster) {
        this.lvl_monster = lvl_monster;
    }

    public void setName_monster(String name_monster) {
        this.name_monster = name_monster;
    }

    public void setHp_monster(int hp_monster) {
        this.hp_monster = hp_monster;
    }

    public void setAtk_monster(int atk_monster) {
        this.atk_monster = atk_monster;
    }

    public void setDef_monster(int def_monster) {
        this.def_monster = def_monster;
    }

    public void setAg_monster(int ag_monster) {
        this.ag_monster = ag_monster;
    }

    public void setG_monster(int g_monster) {
        this.g_monster = g_monster;
    }

    public void setExp_monster(int exp_monster) {
        this.exp_monster = exp_monster;
    }

    public void display(){
        System.out.println("Level: "+this.lvl_monster);
        System.out.println("Name: "+this.name_monster);
        System.out.println("HP: "+this.hp_monster);
        System.out.println("Attack/Damage: "+this.atk_monster);
        System.out.println("Def: "+this.def_monster);
        System.out.println("Ag: "+this.ag_monster);
        System.out.println("Gold: "+this.g_monster);
        System.out.println("Exp: "+this.exp_monster);
    }

}

这是我的主修课,是作战系统

package battlesystem;

public class BattleSystem {

    public static void main(String[] args) {

       Monsters m[] = new Monsters[16];

        //monster-stats
        m[0] = new Monsters(1,"KNOTTY",1000,5,120,34,350,800);
        m[1] = new Monsters(1,"SCORPION",290,10,5,20,336,199);
        m[2] = new Monsters(1,"WERERAT",24,13,100,30,22,21);
        m[3] = new Monsters(1,"ONION KNIGHT",250,13,200,34,350,115);
        m[4] = new Monsters(11,"GOLD BEAR",275,13,40,25,185,160);
        m[5] = new Monsters(11,"RAFLESSIA",2200,13,110,35,767,872);
        m[6] = new Monsters(11,"MEDUSA CHICKEN",2366,13,105,33,422,770);
        m[7] = new Monsters(11,"CHIMERA",2237,25,100,45,760,1144);
        m[8] = new Monsters(11,"MALBORO",2900,30,95,30,2292,780);
        m[9] = new Monsters(21,"GIGANTOS",6000,20,1,50,0,7550);
        m[10] = new Monsters(21,"LEVIATHAN",32000,22,140,61,10000,0);
        m[11] = new Monsters(21,"ABYSS WORM",34000,23,180,42,5000,5000);
        m[12] = new Monsters(31,"AHIRMAN",10000,11,110,30,1000,2820);
        m[13] = new Monsters(31,"IFRIT",3300,25,215,35,7500,5000);
        m[14] = new Monsters(31,"LIZARD",4220,29,90,30,554,1219);
        m[15] = new Monsters(31,"OMEGA",65000,111,222,88,10000,75000);

        //test display
        for(int i = 0; i<m.length; i++) {
         m[i].display();
         System.out.println(" ");
      }
    }

}

我只是想把他们的统计数据打印出来,不管正确与否。谢谢您

gfttwv5a

gfttwv5a1#

如果1是所有怪物攻击的最低分数,那么你可以拥有 atk_monster 变量存储最大可能的攻击存储。如果你想在你的攻击得分中包含随机性,你需要创建一个返回一个 int 使用 Math.random() 还有你的最高分数。
(也可以看看这个)

相关问题