This repository was archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewComputer.java
61 lines (53 loc) · 1.54 KB
/
NewComputer.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package a9;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class NewComputer extends Plant {
private static final int HEALTH = 100;
private static final int COOLDOWN = 5;
private static final int ATTACK_DAMAGE = 1;
private static final BufferedImage IMAGE;
static {
BufferedImage image = null;
try {
image = ImageIO.read(new File("src/a9/game-icons/computer1.png"));
} catch (IOException e) {
System.out.println("A file was not found");
System.exit(0);
}
IMAGE = image;
}
/***
* Creates a plant of New Computer type with specified plant attributes at a
* given position.
*
* @param position
*/
public NewComputer(Point2D.Double position) {
super(position, new Point2D.Double(IMAGE.getWidth(), IMAGE.getHeight()), IMAGE, HEALTH, COOLDOWN,
ATTACK_DAMAGE);
}
/***
* When the New Computer attacks, it will attack colliding Viruses (with no
* cooldown) but will also attack the first Hacker in the actors array list (The
* Hacker the farthest down the line).
*
* @param other
*/
@Override
public void attack(Actor other) {
// Attacks Hacker farthest down the line with a cooldown.
if (this.isReadyForAction()) {
if (other instanceof Hacker) {
other.changeHealth(-attackDamage);
this.resetCoolDown();
}
}
// Attacks colliding viruses with no cooldown so they cannot spread.
if (other instanceof Virus && this.isCollidingOther(other)) {
other.changeHealth(-attackDamage);
}
}
}