I just create a class SpaceInvadersGame like below, and still not true :|
Today we invite you to write an exciting game — Space Invaders. As always, we'll start with the rules.
- The object of the game is for the player to destroy every alien spaceship.
- The player controls a laser cannon and can move it left and right at the bottom of the screen.
- The player has an unlimited supply of "laser projectiles". When the player hits an alien ship, he or she kills it and receives some points.
- When the game begins, the alien ships are located at the top of the screen. They move horizontally and, upon reaching the edge of the playing field, descend to the next row, gradually getting closer to the player.
- As the number of alien ships decreases, the remaining ships begin to move faster.
- After all the aliens are destroyed, the player wins.
- The aliens try to destroy the player's cannon by shooting at it. If an alien hits the cannon, the player loses.
- If even one alien reaches the bottom of the screen, the alien invasion succeeds and the game ends.
- A "boss" is located above the rows of alien ships. If the player destroys the boss, he or she receives bonus points.
Let's begin. To start, we'll need a SpaceInvadersGame class that inherits the Game class. It has methods that will help us write the game.
Now we'll set up the playing field. To start the game, we need to override the initialize() method, which in turn must call the setScreenSize(int, int) method.
This method sets the playing field's width and height, which it takes as arguments. We'll store them in variables.
To complete the Space Invaders task successfully, we recommend that you read this article about the "Games" section. It contains information that you'll find helpful when writing games.
Requirements:
- There must be a public SpaceInvadersGame class.
- The SpaceInvadersGame class must inherit the Game class.
- The SpaceInvadersGame class must have a public static final int WIDTH field, initialized to 64 when it is declared.
- The SpaceInvadersGame class must have a public static final int HEIGHT field, initialized to 64 when it is declared.
- In the SpaceInvadersGame class, the initialize() method of the Game parent class must be overridden.
- The Game class's setScreenSize(int, int) method must be called with arguments (WIDTH, HEIGHT) in the initialize() method.
- The SpaceInvadersGame class must have a statement that imports the entire contents of the com.codegym.engine.cell package.
import com.codegym.engine.cell.*;
public class SpaceInvadersGame extends Game {
public static final int WIDTH = 64;
public static final int HEIGHT = 64;
@Override
public void initialize() {
setScreenSize(WIDTH,HEIGHT);
}
}