-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase.java
More file actions
63 lines (53 loc) · 1.32 KB
/
Copy pathBase.java
File metadata and controls
63 lines (53 loc) · 1.32 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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.util.*;
import javax.imageio.ImageIO;
public class Base {
private int money;
private int maxHealth;
private int currentHealth;
private Image img;
public Base(int maxHealth, int currentHealth) {
this.maxHealth = maxHealth;
this.currentHealth = currentHealth;
this.money = 500;
try {
img = ImageIO.read(new File("castle.png"));
} catch (Exception e) {
System.out.println("BASE: No Image Found");
}
}
public void collision(int enemyHealth) {
this.currentHealth -= enemyHealth;
}
public boolean gameOver() {
if (this.currentHealth < 0) {
return true;
}
return false;
}
public void heal() {
this.currentHealth += (maxHealth - currentHealth) * 0.2;
}
public void draw(Graphics g) {
// Draw base
g.drawImage(img, 325, 125, null);
// Draw health Bar
double ratio = (double) currentHealth / maxHealth;
g.setColor(Color.RED);
g.fillRect(345, 100, 200, 25);
g.setColor(Color.GREEN);
g.fillRect(345, 100, (int)(200 * ratio), 25);
}
public int getHealth() {
return this.currentHealth;
}
public int getMoney() {
return this.money;
}
public void changeMoney(int num) {
this.money += num;
}
}