-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathEnemy.java
More file actions
76 lines (64 loc) · 1.48 KB
/
Enemy.java
File metadata and controls
76 lines (64 loc) · 1.48 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
65
66
67
68
69
70
71
72
73
74
75
76
package org.project.entity.enemies;
import org.project.object.weapons.Weapon;
public abstract class Enemy implements Entity {
protected Weapon weapon;
private int maxHP;
private int maxMP;
private int hp;
private int mp;
public Enemy(int hp, int mp, Weapon weapon) {
this.maxHP = hp;
this.maxMP = mp;
this.hp = hp;
this.mp = mp;
this.weapon = weapon;
}
@Override
public void attack(Entity target) {
if (weapon != null) {
System.out.println("Enemy attacks with " + weapon.getName());
target.takeDamage(weapon.getDamage());
} else {
System.out.println("Enemy has no weapon to attack!");
}
}
@Override
public void takeDamage(int damage) {
hp -= damage;
if (hp <= 0) {
hp = 0;
System.out.println("Enemy has been defeated!");
}
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
}
@Override
public int getMaxHP() {
return maxHP;
}
@Override
public int getMaxMP() {
return maxMP;
}
public int getHp() {
return hp;
}
public int getMp() {
return mp;
}
public Weapon getWeapon() {
return weapon;
}
}