-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
64 lines (49 loc) · 1.3 KB
/
Knight.java
File metadata and controls
64 lines (49 loc) · 1.3 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 Knight in a game
*
*/
public class Knight extends GameCharacter {
/**
*
* @param name the name of the Knight
* @param x the initial x-coordinate of the Knight
* @param y the initial y-coordinate of the Knight
*/
public Knight(String name, int x, int y) {
super(name, x, y, "Knight");
Knight knight =
}
/**
* Causes the Knight to attack the { @code target }
* @param target the GameCharacter target to attack
*/
@Override
public boolean attack(GameCharacter target) {
if (this.isInActive()) {
return false;
}
double distance = this.getDistanceFrom(target);
if (distance <= 5) {
target.decreaseHealthPoints(20);
return true;
}
return false;
}
/**
* Causes the Knight to move in { @code direction } for { @code distance }
* @param direction the direction to move. Could be 'N', 'S', 'E', 'W' for North, South, East and West
* @param distance the distance for the Knight to move
*/
@Override
public void move(char direction, int distance) {
if (distance > 2) {
distance = 2;
}
if (distance < 0) {
distance = 0;
}
super.move(direction, distance);
}
}