-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.java
More file actions
40 lines (38 loc) · 993 Bytes
/
Copy pathCharacter.java
File metadata and controls
40 lines (38 loc) · 993 Bytes
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
public abstract class Character {
private String name;
private int health;
private int attackPower;
Character(String name,int health, int attackPower){
this.name = name;
this.health = health;
this.attackPower = attackPower;
}
public boolean isAlive(){
return this.health > 0;
}
public void takeDamage(int damage) {
health -= damage;
if (health < 0) {
health = 0;
}
System.out.println(name + " took " + damage + " damage. Health now: " + health);
}
public int getAttackPower() {
return attackPower;
}
public void setAttackPower(int attackPower) {
this.attackPower = attackPower;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
}