-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
54 lines (53 loc) · 1.56 KB
/
Player.java
File metadata and controls
54 lines (53 loc) · 1.56 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
public class Player{
protected String name;
protected int health;
protected int minDamage;
protected int maxDamage;
public Player(String inputName, int hP, int minD, int maxD){
name = inputName;
health = hP;
minDamage = minD;
maxDamage = maxD;
}
public String getName(){
return name;
}
public int getHealth(){
return health;
}
public int getMinDamage(){
return minDamage;
}
public int getMaxDamage(){
return maxDamage;
}
public void setName(String newName){
name = newName;
}
public void setHealth(int newHP){
health = newHP;
}
public void setMinDamage(int newMinD){
minDamage = newMinD;
}
public void setMaxDamage(int newMaxD){
maxDamage = newMaxD;
}
public void receiveDamage(int damage){
if (health - damage >=0){
health = health - damage;
System.out.println(name + "has " + health + "health left.");
}
else
System.out.println(name + "is dead.");
}
public void attack(Player enemy){
int hitDamage = (int) ((Math.random() * (maxDamage-minDamage+1)) + minDamage);
enemy.setHealth(enemy.getHealth() - hitDamage);
if (enemy.getHealth() <= 0)
enemy.setHealth(0);
System.out.println(this.name + " attacks " + enemy.getName() + " doing " + hitDamage + " damage.");
System.out.println(enemy.getName() + " has " + enemy.getHealth() + " health left.");
System.out.println();
}
}