-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathEnemy.java
More file actions
97 lines (85 loc) · 1.97 KB
/
Enemy.java
File metadata and controls
97 lines (85 loc) · 1.97 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.object.weapons.Weapon;
import java.lang.Math;
import static java.lang.Math.min;
public abstract class Enemy implements Entity {
Weapon weapon;
private int lvl;
private int hp;
private final int MaxHP;
private boolean IsDefending=false;
protected boolean IsDead=false;
//constructor
public Enemy(int lvl,double hpMult, Weapon weapon) {
this.lvl=lvl;
this.hp = (int)(lvl*hpMult)*100;
this.MaxHP = this.hp;
this.weapon = weapon;
}
//resets player's status each round
@Override
public void reset()
{
this.IsDefending=false;
}
//taking damage
@Override
public void takeDamage(int damage) {
if(!IsDefending) {
hp -= damage;
}
else {
hp -= damage/(int)(Math.sqrt(lvl)*2);
}
if(this.hp <= 0) {
IsDead=true;
this.hp = 0;
}
}
//attack
@Override
public void attack(Entity target) {
int damage = (int)((getWeapon().getDamage())*(Math.sqrt(getLevel())));
target.takeDamage(damage);
}
//heal
@Override
public void heal(int health) {
hp = min(hp + health, MaxHP);
}
//getter methods
@Override
public boolean isDefending(){
return IsDefending;
}
@Override
public int getHP() {
return hp;
}
public int getLevel(){
return lvl;
}
public int getMaxHP() {
return MaxHP;
}
public Weapon getWeapon() {
return weapon;
}
public boolean isDead() {
return IsDead;
}
public boolean isResurrected()
{
return false;
}
//getting enemy status
abstract public String getStatus();
//setter methods
public void setLevel(int lvl){
this.lvl=lvl;
}
public void DefendStatusChange() {
IsDefending = !IsDefending;
}
}