-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonster.java
39 lines (32 loc) · 1.02 KB
/
Monster.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
class Monster {
private String nama;
private int health;
private int damage;
public int defense;
public Monster(String nama, int health, int damage, int defense) {
this.nama = nama;
this.health = health;
this.damage = damage;
this.defense = defense;
}
public String getName() {
return nama;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public int getDamage() {
return damage;
}
public void attack(Player player) {
System.out.println(nama + " attack " + player.getName() + "!");
int damageDealt = Math.max (0, damage - player.defense);
player.setHealth(player.getHealth() - damageDealt);
System.out.println(player.getName() + " menerima " + damageDealt + " damage.");
System.out.println(player.getName() + " health: " + player.getHealth());
System.out.println();
}
}