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.
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.