【发布时间】:2012-03-01 14:35:09
【问题描述】:
我有一个作业问题,我必须制作一个继承程序,该程序由一个名为 dungeonCharacter 的类组成,有两个子类 Hero 和 Monster,它们有 3 个自己的子类,它们有一定的差异,等等。我有主要类 dungeonCharacter 的麻烦。这是描述:
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.80 一样通过,这意味着 80% 的命中率,我如何检查攻击是否有效?
-
@anthony,在没有任何硬数据的情况下,制定您自己的标准。只要它是合理的,并且你可以在质疑时证明它是合理的,你就应该做好准备。
标签: java inheritance constructor polymorphism