Help
Everything will move in the game, which means that we need to specify the direction in which objects are moving. It is convenient to store directions in an enum.
We'll describe the motion of an enemy ship in the move() method. The method will change the appropriate coordinate depending on direction and speed. The downward speed will be a constant 2.
Because the enemy fleet moves back and forth between edges of the playing field, we need to watch for when the fleet reaches the edges.
Requirements:
- There must be a public Direction enum with the following values in a separate file: RIGHT, LEFT, UP, DOWN.
- The EnemyShip class must have a public void move(Direction direction, double speed) method.
- In the move(Direction direction, double speed) method, you need to increase the x field by speed if direction is equal to Direction.RIGHT.
- In the move(Direction direction, double speed) method, you need to decrease the x field by speed if direction is equal to Direction.LEFT.
- In the move(Direction direction, double speed) method, you need to increase the y field by 2 if direction is equal to Direction.DOWN.
- The EnemyFleet class must have a private double getLeftBorder() method.
- The getLeftBorder() method must return the smallest x coordinate of all of the enemy ships in the ships list.
- The EnemyFleet class must have a private double getRightBorder() method.
- The getRightBorder() method must return the largest (x + width) value of all of the enemy ships in the ships list.
package com.codegym.games.spaceinvaders;
public enum Direction {
RIGHT,
LEFT,
UP,
DOWN;
}