Let's continue working on the enemy fleet. To do this, we need to fill the ships list in the createShips() method.
Keep in mind that the best distance from the top of the screen to the top row of ships is 12 cells.
To add the enemy fleet to the game, we'll create an enemyFleet field in the SpaceInvadersGame class and initialize it to a new EnemyFleet object. The enemy ships are created when the createShips method is called in the EnemyFleet constructor.
The game is dynamic, so we'll need to regularly redraw the screen and perform other actions. Everything that happens at each step is performed in the onTurn(int) method.
We'll use the setTurnTimer method to set how often this method is called. It takes an argument that determines how long each step is in milliseconds. In other words, given a step of 40 ms (0.04 second), the onTurn method will be called 25 times per second (1 / 0.04 second). If you've done everything correctly, you'll see the enemy fleet when you run the program.
- In the EnemyFleet class's createShips() method, you need to create ROWS_COUNT * COLUMNS_COUNT enemy ships and add them to the ships list.
- Each enemy ship must be created with the arguments: x * STEP, y * STEP + 12, where x is a loop counter from 0 (including 0) to COLUMNS_COUNT (not including COLUMNS_COUNT), and y is a loop counter from 0 (including 0) to ROWS_COUNT (not including ROWS_COUNT).
- The EnemyFleet class must have one public no-argument constructor.
- The EnemyFleet class's constructor must call the createShips() method.
- The EnemyFleet class must have a public void draw(Game game) method.
- In the draw(Game game) method, call the draw(Game) method on each enemy ship in the ships list. Pass game as the argument.
- The SpaceInvadersGame class must have a private EnemyFleet enemyFleet field.
- The enemyFleet field must be initialized with a new EnemyFleet object in the createGame() method before the call to the drawScene() method.
- In the drawScene() method, the draw(Game) method must be called on the enemyFleet object after the call to the drawField() method. Pass "this" to the method.
- In the SpaceInvadersGame class, the onTurn(int) method of the Game parent class must be overridden.
- The drawScene() method must be called in the onTurn(int) method.
- In the SpaceInvadersGame class's createGame() method, the Game class's setTurnTimer(int) method must be called with 40 as the argument.
- The EnemyFleet class must import the com.codegym.engine.cell.Game class.