-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcher.java
More file actions
64 lines (48 loc) · 1.41 KB
/
Archer.java
File metadata and controls
64 lines (48 loc) · 1.41 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
*
* @author Sanjeeb Sangraula
* This class represents a Archer in a game
*/
public class Archer extends GameCharacter {
/**
*
* @param name the name of the Archer
* @param x the initial x-coordinate of the Archer
* @param y the initial y-coordinate of the Archer
*/
public Archer(String name, int x, int y) {
super(name, x, y, "Archer");
}
/**
* Overriding the abstract method from the GameCharacter class.
* @param target the GameCharacter that this Archer is to attack
*/
@Override
public boolean attack(GameCharacter target) {
if (this.isInActive()) {
return false;
}
double distance = this.getDistanceFrom(target);
if (distance <= 30) {
target.decreaseHealthPoints(10);
return true;
}
return false;
}
/**
* Causes the Archer to move in { @code direction } for { @code distance }.
* If the distance is greater than 5, it's reduced to 5 and if it's negative then its converted to zero.
* @param direction the direction to move. Could be 'N', 'S', 'E', 'W' for North, South, East and West
* @param distance the distance for the Archer to move
*/
@Override
public void move(char direction, int distance) {
if (distance > 5) {
distance = 5;
}
if (distance < 0) {
distance = 0;
}
super.move(direction, distance);
}
}