gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:58:57 25 4
gpt4 key购买 nike

我有一个家庭作业问题,我必须制作一个继承程序,该程序由一个名为 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 在我看来非常模糊,我很难理解。而老师是无用的。感谢您的帮助!如果我能把这篇文章写下来,剩下的应该很容易。

最佳答案

在没有任何硬数据的情况下,制定自己的标准。只要合理,并且你能在质疑中证明它的合理性,你就应该准备好了。事实上,这个变量被称为施加伤害的“机会”,这对我来说表明存在概率分布,这意味着 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!");
}
}

关于java 继承多态方法 地下城怪物游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com