-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarrior.java
48 lines (40 loc) · 1.25 KB
/
Warrior.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class Warrior extends Enemy implements Fighter {
/** Warrior class extends from Enemy and incorporates the methods of attacks and abilities that the enemies have
@param n the name of the character
@param mHp the maximum health points of the character
*/
public Warrior(String n, int mHp) {
super(n, mHp);
}
/** attack the choice of attack that the Warrior will use
*/
@Override
public String attack(Hero h) {
int attack;
attack = (int)(Math.random() * 2) + 1;
if(attack == 1){
return sword(h);
}
else{
return axe(h);
}
}
/** sword one of the two attacks that the Warrior has
@param e the character which correlates to the attack
*/
@Override
public String sword (Entity e) {
int damage = (int)( Math.random() * 5) + 3;
e.takeDamage(damage);
return getName() + " slashes " + e.getName() + " with a sword for " + damage + " damage";
}
/** axe one of the two attacks that the Warrior has
@param e the character which correlates to the attack
*/
@Override
public String axe (Entity e) {
int damage = (int)( Math.random() * 5) + 3;
e.takeDamage(damage);
return getName() + " slashes " + e.getName() + " with an axe for " + damage + " damage";
}
}