Created
February 8, 2011 06:06
-
-
Save James-Firth/815966 to your computer and use it in GitHub Desktop.
Finished off the fight method and added the Greater Elves to the army
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void createArmy(ArrayList <Enemy> enemies, int numberOfEnemies) | |
{ | |
for (int i = 0; i < numberOfEnemies; i++) | |
{ | |
enemies.add(new Elf()); | |
enemies.add(new GreaterElf()); | |
} | |
} | |
private static boolean fight(Player me, ArrayList<Enemy> army) | |
{ | |
int damage; | |
boolean meDead=false; | |
//all enemies attack | |
for(int x=0; x < army.size() && meDead==false; x++) | |
{ | |
//Does damage and checks if the GElf does a 'critical' | |
damage = army.get(x).dealDamage(); | |
if(damage > 8) | |
{ | |
System.out.println("The Greater Elf hits you for massive damage!"); | |
} | |
else | |
{ | |
System.out.println("The Enemy deals "+damage+" to you!"); | |
} | |
meDead = me.hit(damage); //checks if you're dead | |
if(meDead) | |
{ | |
return false; | |
} | |
else | |
{ | |
System.out.println("Current HP: "+me.getCurrentHP()+"\n"); //if you're not it shows your HP | |
} | |
} | |
//Now it's your turn to fight back! (Only if you're alive) | |
for(int p=0; p < army.size() && meDead==false; p++) | |
{ | |
//Gets your damage and applies it to the enemy | |
damage = me.dealDamage(); | |
army.get(p).hit(damage); | |
System.out.println("You attack the enemy for "+damage+" damage!\n"); | |
if(army.get(p).getCurrentHP() <= 0) | |
{ //then tells you if it's dead or not. | |
System.out.println("The enemy is dead!"); | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment