-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKata.java
More file actions
25 lines (24 loc) · 1018 Bytes
/
Kata.java
File metadata and controls
25 lines (24 loc) · 1018 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
/**
* Created by Lukas on 2017-02-06.
*/
public class Kata {
public static String declareWinner(Fighter fighter1, Fighter fighter2, String firstAttacker) {
if(firstAttacker == fighter2.name)
attack(fighter2, fighter1);
while(true){
attack(fighter1, fighter2);
if(fighter2.health <= 0)
return fighter1.name;
attack(fighter2, fighter1);
if(fighter1.health <= 0)
return fighter2.name;
}
}
public static void attack(Fighter attacker, Fighter defender){
defender.health -= attacker.damagePerAttack;
if(defender.health <= 0)
System.out.println(attacker.name + " attacks " + defender.name + "; " + defender.name + " now has " + defender.health + " health and is dead. " + attacker.name + " wins.");
else
System.out.println(attacker.name + " attacks " + defender.name + "; " + defender.name + " now has " + defender.health + " health.");
}
}