.
package com.codegym.games.spaceinvaders;
import java.util.*;
import com.codegym.engine.cell.*;
import com.codegym.games.spaceinvaders.gameobjects.Star;
public class SpaceInvadersGame extends Game{
public static final int WIDTH = 64;
public static final int HEIGHT = 64;
private List<Star> stars;
final Random random = new Random();
private void createStars() {
stars = new ArrayList<Star>();
int x = 0;
int y = 0;
int xd = 0;
int yd = 0;
int xa = 1;
int xb = 15;
int ya = 1;
int yb = 30;
for(int z = 0; z < 8; z++) {
x = xd + xa + random.nextInt(xb - xa + 1);
y = ya + random.nextInt(yb - ya + 1);
stars.add(z, new Star(x, y));
xd += 16;
if (z == 3) {
xd = 0;
}
if (z == 3) {
ya += 30;
yb += 25;
}
}
}
public void initialize() {
setScreenSize(WIDTH, HEIGHT);
createGame();
}
private void createGame() {
createStars();
drawScene();
}
private void drawScene() {
drawField();
}
private void drawField() {
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
setCellValueEx(x, y, Color.BLACK, "");
}
}
for(Star a : stars) {
a.draw(this);
}
}
}