-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarrior.java
More file actions
22 lines (20 loc) · 850 Bytes
/
Warrior.java
File metadata and controls
22 lines (20 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class Warrior extends Hero{
protected double critChance;
public Warrior(String name, String[] input){
super(name, 100, 20, 10, input);
critChance = 0.5;
}
public void attack(Player enemy){
int hitDamage = (int) ((Math.random() * (maxDamage-minDamage+1)) + minDamage);
if (critChance > Math.random()){
hitDamage = hitDamage * 2;
System.out.println(name + " gets a critical hit!");
}
enemy.setHealth(enemy.getHealth() - hitDamage);
System.out.println(this.name + " attacks the " + enemy.getName() + " doing " + hitDamage + " damage.");
if (enemy.getHealth() <= 0)
enemy.setHealth(0);
System.out.println(enemy.getName() + " has " + enemy.getHealth() + " health left.");
System.out.println();
}
}