At this stage, we'll add a checkHit(List<Bullet> bullets) method for checking whether the player's projectile has hit an enemy ship.
After a hit, we need to "kill" the corresponding projectile and enemy ship. Additionally, we'll add a deleteHiddenShips() method that will remove "hidden" ships from the list.
To remove the ships, you can either use an iterator, or create a copy of the ships list and run through it in a loop. If we determine that a ship needs to be removed, we'll call ships.remove(ship).
The checkHit(List<Bullet> bullets) and deleteHiddenShips() methods must be called in the SpaceInvadersGame class's check() method.
Requirements:
- The EnemyFleet class must have a public void checkHit(List<Bullet> bullets) method.
- In the checkHit(List<Bullet> bullets) method, you need to use the isCollision(GameObject) method to check whether each enemy ship in the ships list has collided with any of the projectiles in the bullets list.
- If a ship and projectile have collided (the isCollision(GameObject) method returns true) and the ship is "alive" and the projectile is "alive", you need to call the kill() on them.
- The EnemyFleet class must have a public void deleteHiddenShips() method.
- The deleteHiddenShips() method must remove from the ships list all ships that are not visible on the playing field (ship.isVisible() == false).
- In the SpaceInvadersGame class's check() method, you need to call the checkHit(List<Bullet>) method with playerBullets as the argument on the enemyFleet object before the call to the removeDeadBullets() method.
- In the SpaceInvadersGame class's check() method, you need to call the deleteHiddenShips() method on the enemyFleet object after the checkHit(List<Bullet>) method.
package com.codegym.games.spaceinvaders;
public enum Direction {
RIGHT,
LEFT,
UP,
DOWN
}