-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
44 lines (36 loc) · 1.17 KB
/
Player.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
class Player {
private String nama;
private int health;
private int damage;
public int defense;
public Player(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(Monster monster) {
System.out.println(nama + " attack " + monster.getName() + "!");
int damageDealt = Math.max (0, damage - monster.defense);
monster.setHealth(monster.getHealth() - (damageDealt));
System.out.println(monster.getName() + " menerima " + damageDealt + " damage.");
System.out.println(monster.getName() + " health: " + monster.getHealth());
System.out.println();
}
public void defenseUp(Player player) {
System.out.println(nama + "Melakukan Defense up");
defense = 10;
}
}