/** * This is the Game.java file posted in the Project4 project * description. It contains only the nextFight method. Students * must complete the remainder of the Game methods and add the * Game instance variables. */ package proj4; import java.util.Vector; // SMM, 11/13/12: I renamed Game_MethodOnly to Game before posting public class Game_MethodOnly implements GameInterface { /******************** instance variables ********************/ /*************** methods declared in GameInterface ****************/ /** * Determine if the invasion is over. If the invasion is over, all * remaining ants' health reset to full life. * @return true if there are no ants or no zombies remaining. */ public void nextFight() { Ant a = colony.elementAt(0); a.attack(this); Zombie z = horde.elementAt(0); if ((a instanceof LeafcutterAnt) && (z.getLife() <= 0)) { // leafcutters have first strike, so opposing zombie gets no attack } else { z.attack(this); } // reap all things dead boolean keepReaping = true; while (keepReaping) { keepReaping = false; for (int i = 0; i < colony.size(); ) { a = colony.elementAt(i); if (a.getLife() > 0) { i++; } else { colony.remove(i); if (a instanceof CitronellaAnt) { for (Ant a2 : colony) { a2.takeDamage(2); } for (Zombie z2: horde) { z2.takeDamage(2); } } keepReaping = true; } } for (int i = 0; i < horde.size(); ) { z = horde.elementAt(i); if (z.getLife() > 0) { i++; } else { horde.remove(i); food += z.getReward(); } } } if (colony.size() == 0 && horde.size() > 0) { gameOver = true; } } /******************** other methods ********************/ }