The program works as expected, but does not meet the 6th and 7th requirements somehow. Is this because I used a Random object for the
new Star(x, y)
parameters?//FILE CREATED ON: 5/25/22
package com.codegym.games.spaceinvaders;
import com.codegym.engine.cell.*;
import com.codegym.games.spaceinvaders.gameobjects.Star;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class SpaceInvadersGame extends Game {
//====================================== VARIABLES
public static final int WIDTH = 64;
public static final int HEIGHT = 64;
private List<Star> stars;
public Random random = new Random();
//====================================== METHODS
@Override
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.DARKORCHID, "");
}
}
for (Star s : stars ) {
s.draw(this);
}
}
private void createStars() {
stars = new ArrayList<Star>();
for (int i = 0; i < 8; i++) {
int randX = random.nextInt(WIDTH);
int randY = random.nextInt(HEIGHT);
stars.add(new Star(randX, randY));
}
}
}