- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个家庭作业问题,我必须制作一个继承程序,该程序由一个名为 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/
我走! 农卡! 乡非! 男痴@ 有倪 再贱 罗二。 左耳L 鱼七° 闲人 只要你! 怪物 - 久伴! 兀自
我即将编写一个将条形码转换为游戏元素(例如怪物、元素、技能等)的游戏。很像旧的“Barcode Battler”游戏。 不幸的是,我在数学方面不是很有天赋。我需要的是一些提示,我可以如何开发一种算法来
冒着听起来像新手程序员的风险,我要问一个关于“空指针”怪兽的普遍存在的问题。这是一段代码: public class pixel { private String type = "empty"
我正在接手一个庞大的现有项目。现在我正在寻找一些错误。但是当到处都是 symfony 缓存时,很难理解外国代码做了什么。 Quit the server with CONTROL-C. RUN
我们当前的自动化构建由 1 个主盒和 4 个 core-2-duo 披萨盒(大约 2.5Ghz)组成,每个盒有 3 GB 内存,全部运行 Ubuntu Linux。 (使用bamboo) 我被要求重新
我有一个它正在选择的怪物列表。 def monsters(): whatMonster = random.randint(0, 25) monster = pickMonste
我是一名优秀的程序员,十分优秀!