/** * Remove enemies that are either out of bound or dead. Also checks if this wave is defeated. If * it is, starts a new wave and adds 25 to the money * * @return none */ private void remove() { Iterator<Enemy> iterator = enemies.iterator(); while (iterator.hasNext()) { Enemy enemy = iterator.next(); if (enemy.isDead() || enemy.isOutOfBound()) { iterator.remove(); } if (enemies.isEmpty()) { money += 25; TowerDefenseGame.getControlPanel().newWave(); } } }
/** * Checks the status, out of bound, dead of all the enemies. Also checks if the game is over. * * @return none. */ private void checkStatus() { for (Enemy enemy : enemies) { if (enemy.isOutOfBound()) { life -= enemy.decreaseLife; if (life < 0) { life = 0; } // Refreshes the control panel to reflect changes in numbers TowerDefenseGame.getControlPanel().refresh(); } else if (enemy.isDead()) { money += enemy.increaseMoney; TowerDefenseGame.getControlPanel().refresh(); } if (life <= 0) { timer.stop(); JOptionPane.showMessageDialog(this, "Game Over", "Gave Over", JOptionPane.PLAIN_MESSAGE); System.exit(0); } } }