Here is my current code.
import java.util.*;
public class Battle
{
ArrayList<String> zombies = new ArrayList<String>();
Random rand = new Random();
public void battle()
{
Scanner input = new Scanner(System.in);
int zombieHealth = 20 + rand.nextInt(40);
int playerHealth = 50;
boolean win = true;
zombies.add("Zombie Math Teacher");
// zombies.add("Zombie English Teacher");
// zombies.add("Zombie Science Teacher");
System.out.print("You have encountered a...");
//zombies.add("Zombie Math Teacher");
//Collections.shuffle(zombies);
for (int i = 0; i < zombies.size(); i++)
System.out.printf(" %s", zombies.get(i));
do
{
System.out.print("\nEnter A to attack:");
char attack = input.nextLine().charAt(0);
int playerDmg = rand.nextInt(6);
if (playerDmg == 0)
System.out.printf("You Missed\nZombie Health: %d\n",
zombieHealth -= playerDmg );
else
for (int i = 0; i < zombies.size(); i++)
System.out.printf("You hit the %s for %d damage\n Zombie Health: %d\n",
zombies.get(i), playerDmg, zombieHealth -= playerDmg);
int zombieDmg = rand.nextInt(3);
if (zombieDmg == 0)
for (int i = 0; i < zombies.size(); i++)
System.out.printf("The %s Missed\nPlayer Health: %d\n",
zombies.get(i), playerHealth -= zombieDmg);
else
for (int i = 0; i < zombies.size(); i++)
System.out.printf("The %s hits you for %d damage\n Your Health: %d\n",
zombies.get(i), zombieDmg, playerHealth -= zombieDmg);
if (zombieHealth <= 0)
{
zombieHealth = 0;
win = true;
}
else
win = false;
}while (win != true);
if (zombieHealth <= 0)
{
zombieHealth = 0;
System.out.print("You WIN!\n\n");
zombies.remove("Zombie Math Teacher");
}
else
{
playerHealth = 0;
System.out.print("Game Over\n\n");
}
}
}
Any help would be appreciated.
P.S. I would also like to figure out how to remove the zombie permanently so he doesn't show up again.
Thanks again.

New Topic/Question
Reply



MultiQuote




|