Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 09e4c66

Browse files
author
garax91
committed
Merge pull request #25 from dhaunac/combat2b
Combat attack
2 parents 3dc7b9e + 2cc1822 commit 09e4c66

13 files changed

Lines changed: 440 additions & 134 deletions

File tree

src/combat/Attacks.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,52 @@
55
import java.util.Random;
66

77
public class Attacks {
8-
8+
99
private String name;
1010
private static ArrayList<String> attackNames = new ArrayList<String>(Arrays.asList(
1111
new String[] { "Feuerwerfer", "Wasserbombe", "Pustekuchen", "Erdloch", "Schmetterball", "Traubenwerfer",
1212
"Rutschschlag", "Faustschlag", "Ausruhen", "Sein Leben chillen", "Stecker ziehen" }));
13+
14+
private int attackDmg;
1315

14-
public Attacks(String name) {
15-
this.name = name;
16-
}
17-
16+
//generate name + attackDmg
1817
public Attacks() {
19-
Random rnd = new Random();
20-
this.name = attackNames.get(rnd.nextInt(attackNames.size() - 1));
18+
this(new Random().nextInt(40) + 10, attackNames.get(new Random().nextInt(attackNames.size() - 1)));
2119
}
22-
20+
21+
//generate name
22+
public Attacks(int attackDmg) {
23+
this(attackDmg, attackNames.get(new Random().nextInt(attackNames.size() - 1)));
24+
}
25+
26+
//save attackDmg and name
27+
public Attacks(int attackDmg, String name) {
28+
this.name = name;
29+
this.attackDmg = attackDmg;
30+
}
31+
32+
33+
2334
public String getName() {
2435
return name;
2536
}
37+
38+
public void doAttack(IAttackable focus) {
39+
doAttack(focus, null);
40+
}
41+
public void doAttack(IAttackable focus, Combo combo) {
42+
int dmg = attackDmg;
43+
float luck = new Random().nextFloat() + 0.5f;
44+
dmg *= luck;
45+
if(combo != null){
46+
dmg += dmg * combo.getCombo().length / 10f; //for each combo step get 10% extra dmg
47+
}
48+
focus.getDmg(dmg);
49+
}
50+
51+
52+
public int getDamage(){
53+
return attackDmg;
54+
}
2655

2756
}

0 commit comments

Comments
 (0)