java 继承多态方法 地下城怪物游戏

发布于 2025-01-03 11:47:33 字数 1901 浏览 0 评论 0原文

我有一个家庭作业问题,我必须制作一个继承程序,该程序由一个名为 dungeonCharacter 的类组成,有两个子类 Hero 和 Monster,它们有 3 个自己的子类,这些子类有一定的差异,等等。我遇到了麻烦主要类别的地下城角色。这是描述:

DungeonCharacter (base - abstract)
contains instance variables that any character in the game will have -- protected access     is ok (NO public access allowed!) 
o name - String
o hit points (how much damage a character can take before it expires) - integer
o attack speed - integer (1 is slowest)
o damage range (minimum and maximum amount of damage a character can do on an 
attack) - two integers
o chance to hit opponent when attacking - double
o anything else you deem necessary
 constructor to initialize instance variables get and set methods as you deem necessary
 an attack method 
o first checks if character can attack (based on chance to hit)
o if it can, a hit in range of minimum to maximum damage is generated and applied to 
opponent -- user should be informed of what happens
o if it cannot, a message should be displayed that says the attack failed

这是我的代码,我很难真正理解一些事情,特别是攻击方法和命中机会。我不知道如何开始,也不知道从这里该去哪里。到目前为止,这是我的代码。

public abstract class DungeonCharacter {
    protected String name;
    protected int hitPoints;
    protected int speed;
    protected int minRange;
    protected int maxRange;
    protected double chance;

    public DungeonCharacter(String name, int hitPoints, int speed,
int minRange, int maxRange, int chance) {
        this.name = name;
        this.hitPoints = hitPoints;
        this.speed = speed;
        this.minRange = minRange;
        this.maxRange = maxRange;
        this.chance = chance;
    }

    public void setString(String newName) {
        name = newName;
    }

    public String getName() {
        return name;
    }

    public void Attack() {

    }
}

请帮助我理解这一点并找到必要的代码来完成指示,在我看来这个 hwk 非常模糊,我很难理解。而老师是无用的。感谢您的帮助!如果我能把这篇文章写下来,剩下的应该很容易。

I have a homework problem where I have to make an inheritance program that consists of a class called dungeonCharacter, with two child classes Hero and Monster, that have 3 of their own subclasses that have certain differences, etc etc. I am having trouble with the main class dungeonCharacter. here is the description:

DungeonCharacter (base - abstract)
contains instance variables that any character in the game will have -- protected access     is ok (NO public access allowed!) 
o name - String
o hit points (how much damage a character can take before it expires) - integer
o attack speed - integer (1 is slowest)
o damage range (minimum and maximum amount of damage a character can do on an 
attack) - two integers
o chance to hit opponent when attacking - double
o anything else you deem necessary
 constructor to initialize instance variables get and set methods as you deem necessary
 an attack method 
o first checks if character can attack (based on chance to hit)
o if it can, a hit in range of minimum to maximum damage is generated and applied to 
opponent -- user should be informed of what happens
o if it cannot, a message should be displayed that says the attack failed

here is my code, i am having a hard time really understanding a few things, in particular, the attack method, and the chance of hitting. I dont know how to get started on that and where to go from here. here is my code so far.

public abstract class DungeonCharacter {
    protected String name;
    protected int hitPoints;
    protected int speed;
    protected int minRange;
    protected int maxRange;
    protected double chance;

    public DungeonCharacter(String name, int hitPoints, int speed,
int minRange, int maxRange, int chance) {
        this.name = name;
        this.hitPoints = hitPoints;
        this.speed = speed;
        this.minRange = minRange;
        this.maxRange = maxRange;
        this.chance = chance;
    }

    public void setString(String newName) {
        name = newName;
    }

    public String getName() {
        return name;
    }

    public void Attack() {

    }
}

please help me understand this and find the necessary code to fulfill the directions, this hwk is very vague in my opinion and Im having a hard time understanding. and the teacher is useless. thanks for helping! if i can just get this written writing the rest should be easy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2025-01-10 11:47:34

在没有任何硬数据的情况下,制定自己的标准。只要合理,并且你能在质疑中证明它的合理性,你就应该准备好了。事实上,这个变量被称为施加伤害的“机会”,这对我来说表明存在概率分布,这意味着 0.0 意味着没有机会击中,1.0 意味着你绝对可以击中。你可以用0.0来思考,大概意味着角色距离太远,无法对敌人造成伤害。 1.0意味着你正站在敌人的正前方。因此,您可以对攻击施加的伤害量取决于攻击的机会以及可以造成的最小/最大伤害。

public void attack() {
    if(chance > 0.0 /* Some arbitrary value */) {
        double damageToApply = minRange + chance*(maxRange - minRange);
        System.out.println("Applying damage: " + damageToApply);
    } else {
        System.out.println("Unable to apply damage, flee!");
    }
}

In the absence of any hard data, make up your own criteria. As long as its reasonable, and you can justify it on questioning, you should be all set. The fact that the variable is called "chance" to apply damage, indicates to me the presence of a probability distribution, which means that 0.0 means no chance of hitting, and 1.0 means that you can absolutely hit. You can think about it in terms of 0.0 probably means that the character is too far away to damage the enemy. 1.0 means you're standing right in front of the enemy. The amount of damage that you could apply on attack would therefore depend on the chance to attack and the minimum / maximum damage that can be dished out.

public void attack() {
    if(chance > 0.0 /* Some arbitrary value */) {
        double damageToApply = minRange + chance*(maxRange - minRange);
        System.out.println("Applying damage: " + damageToApply);
    } else {
        System.out.println("Unable to apply damage, flee!");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文