diff --git a/src/world/Enemy.java b/src/world/Enemy.java index 67c310bd12b639f566b58b154ca6e4273ca543e0..607fcee76e53689e42d0101d5d00eb6708122886 100644 --- a/src/world/Enemy.java +++ b/src/world/Enemy.java @@ -16,13 +16,12 @@ public class Enemy extends Placeable implements ITickable { private Field prevField; private int moveTries; private static HashMap<EnemyType, Integer> moveTimes = new HashMap<EnemyType, Integer>(); - static - { + static { moveTimes.put(EnemyType.HUMAN, 4); moveTimes.put(EnemyType.DWARF, 5); moveTimes.put(EnemyType.ELF, 3); moveTimes.put(EnemyType.HOBBIT, 6); - } + } public Enemy(EnemyType p_type) { type = p_type; @@ -30,7 +29,7 @@ public class Enemy extends Placeable implements ITickable { prevField = null; hp = 100; } - + public void hurt(int dmg) { Random rand = new Random(); @@ -40,18 +39,17 @@ public class Enemy extends Placeable implements ITickable { } else if (rand.nextInt(15) == 0) split(); } - - private void Die() - { + + private void Die() { field.getWorld().notifyEnemyDied(this); field.stepOff(this); - if(this.type == EnemyType.HUMAN) - Sounds.PlaySound("src\\resources\\human_dead.wav"); - if(this.type == EnemyType.DWARF) + if (this.type == EnemyType.HUMAN) + Sounds.PlaySound("src\\resources\\human_dead.wav"); + if (this.type == EnemyType.DWARF) Sounds.PlaySound("src\\resources\\dwarf_dead.wav"); - if(this.type == EnemyType.HOBBIT) + if (this.type == EnemyType.HOBBIT) Sounds.PlaySound("src\\resources\\hobbit_dead.wav"); - if(this.type == EnemyType.ELF) + if (this.type == EnemyType.ELF) Sounds.PlaySound("src\\resources\\elf_dead.wav"); } @@ -72,13 +70,20 @@ public class Enemy extends Placeable implements ITickable { potentials.add(field); } } - if(!potentials.isEmpty()){ - Random rand = new Random(); - int index = rand.nextInt(potentials.size()); - field.stepOff(this); - prevField = field; - reset(); - potentials.get(index).stepOn(this); + if (!potentials.isEmpty()) { + Random rand = new Random(); + int index = rand.nextInt(potentials.size()); + field.stepOff(this); + prevField = field; + reset(); + potentials.get(index).stepOn(this); + } + else + { + field.stepOff(this); + prevField = field; + reset(); + prevField.stepOn(this); } } else { moveTries++; @@ -86,12 +91,13 @@ public class Enemy extends Placeable implements ITickable { } public void split() { - hp=hp/2; + hp = hp / 2; if (hp == 0) { Die(); return; } - field.getWorld().getSpawnManager().spawnEnemy(field, type, hp, prevField); + field.getWorld().getSpawnManager() + .spawnEnemy(field, type, hp, prevField); } private void reset() { @@ -104,7 +110,7 @@ public class Enemy extends Placeable implements ITickable { } public void tick() { - if (moveTimeLeft <= 0 && hp>0) + if (moveTimeLeft <= 0 && hp > 0) move(); else moveTimeLeft--; @@ -113,12 +119,12 @@ public class Enemy extends Placeable implements ITickable { public int getHP() { return hp; } - + public void setHP(int hp) { - this.hp=hp; + this.hp = hp; } - - public void setPrevField(Field f){ - prevField=f; + + public void setPrevField(Field f) { + prevField = f; } } \ No newline at end of file