package com.javarush.games.spaceinvaders;
import com.javarush.engine.cell.*;
import com.javarush.games.spaceinvaders.gameobjects.*;
import java.util.ArrayList;
import java.util.List;
public class SpaceInvadersGame extends Game {
public static final int WIDTH = 64;
public static final int HEIGHT = 64;
private List<Star> stars;
private void createStars(){
stars = new ArrayList<>();
for (int i=0; i < 8; i++) {
stars.add(new Star(getRandomNumber(WIDTH-1), getRandomNumber(HEIGHT-1)));
}
}
@Override
public void initialize(){
setScreenSize(WIDTH, HEIGHT);
createGame();
}
private void createGame(){
createStars();
drawScene();
}
private void drawScene(){
drawField();
}
private void drawField()
{
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
setCellValueEx(x, y, Color.BLACK, "");
}
}
for (int i = 0; i < stars.size(); i++)
{
stars.get(i).draw(this);
}
}
}
package com.javarush.games.spaceinvaders.gameobjects;
import com.javarush.engine.cell.*;
public class Star extends GameObject {
private static final String STAR_SIGN = "\u2605";
public Star(double x, double y) {
super(x, y);
}
public void draw(Game game) {
game.setCellValueEx((int) x, (int) y, Color.NONE, STAR_SIGN, Color.WHITE, 100);
}
}
package com.javarush.games.spaceinvaders.gameobjects;
public class GameObject {
public double x;
public double y;
public GameObject ( double x,double y) {
this.x = x;
this.y = y;
}
}
package com.javarush.games.spaceinvaders;
import com.javarush.engine.cell.*;
import com.javarush.games.spaceinvaders.gameobjects.*;
import java.util.ArrayList;
import java.util.List;
public class SpaceInvadersGame extends Game {
public static final int WIDTH = 64;
public static final int HEIGHT = 64;
private List<Star> stars;
private void createStars(){
stars = new ArrayList<>();
for (int i=0; i < 8; i++) {
stars.add(new Star(getRandomNumber(WIDTH-1), getRandomNumber(HEIGHT-1)));
}
}
@Override
public void initialize(){
setScreenSize(WIDTH, HEIGHT);
createGame();
}
private void createGame(){
createStars();
drawScene();
}
private void drawScene(){
drawField();
}
private void drawField()
{
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
setCellValueEx(x, y, Color.BLACK, "");
}
}
for (int i = 0; i < stars.size(); i++)
{
stars.get(i).draw(this);
}
}
}