код класса который был изменен перед ошибкой.
package com.javarush.games.spaceinvaders;
import com.javarush.engine.cell.Game;
import com.javarush.engine.cell.Key;
import com.javarush.engine.cell.Color;
import com.javarush.games.spaceinvaders.gameobjects.Buttons.*;
import com.javarush.games.spaceinvaders.gameobjects.FoneDecor.*;
import com.javarush.games.spaceinvaders.gameobjects.Objects.*;
import java.util.*;
public class SpaceInvadersGame extends Game {
public static final String VERSION = "v 2.0.1";
public static final int WIDTH = 100;
public static final int HEIGHT = 100;
public static int PlanetCount = 7;
public static boolean STOP = true;
public static int TIMER = StartValue.StartTimer;
public static int LEVEL = StartValue.StartLevel;
public static int Complexity = StartValue.StartComplexity;
private static int PlayerBulletsMax = StartValue.StartPlayerBulletsMax;
private static int PlayerRocketsMax = StartValue.StartPlayerRocketsMax;
private static PlayerShip playerShip;
private List<Star> stars;
private EnemyFleet enemyFleet;
private List<Bullet> enemyBullets;
private Planet planet;
private PlayButton Playbutton;
private PauseButton Pausebutton;
private MenuButton Menubutton;
private StarWars Starwars;
private Sprite WinAndLossText;
private Sprite NumsAndText;
private Sprite FoneLine;
private Sprite RocketSprite;
private Sprite HpSprite;
private List<Bullet> playerBullets;
private List<Bullet> playerRockets;
private boolean InPause = false;
private boolean InMenu = true;
private boolean isGameStopped = false;
private int animationsCount;
private int score;
@Override
public void onMouseRightClick(int x, int y) {
}
@Override
public void onMouseLeftClick(int x, int y) {
if (x >= 34 && x <= 64 && y >= 35 && y <= 50) {
if (InPause) {
menu();
}
}
if (x >= 34 && x <= 64 && y >= 65 && y <= 80) {
if (InMenu) {
createGame();
}
}
if (x >= 90 && x <= 99 && y >= 0 && y <= 12) {
stop();
}
}
@Override
public void initialize() {
showGrid(false);
setScreenSize(WIDTH, HEIGHT);
menu();
}
@Override
public void onTurn(int step) {
moveSpaceObjects();
check();
Bullet bullet = enemyFleet.fire(this);
if (bullet != null) {
enemyBullets.add(bullet);
}
setScore(score);
drawScene();
}
public void stop() {
InMenu = false;
InPause = true;
if (!isGameStopped) {
Menubutton = new MenuButton();
if (STOP) {
STOP = false;
Menubutton.draw(this);
stopTurnTimer();
} else {
STOP = true;
setTurnTimer(TIMER);
}
}
}
public void fireBullet() {
for (int i = 0; i < 2; i++) {
playerShip.BulletNum = i;
playerShip.isRocket = false;
Bullet bullet = playerShip.fire();
if (bullet != null && playerBullets.size() < PlayerBulletsMax) {
playerBullets.add(bullet);
}
}
}
public void fireRocket() {
for (int i = 0; i < 2; i++) {
playerShip.BulletNum = i;
playerShip.isRocket = true;
Bullet bullet = playerShip.fire();
if (bullet != null && playerRockets.size() < PlayerRocketsMax) {
playerRockets.add(bullet);
}
}
}
@Override
public void onKeyPress(Key key) {
if (Key.SPACE == key && isGameStopped) {
createGame();
return;
}
if (Key.LEFT == key) {
playerShip.setDirection(Direction.LEFT);
}
if (Key.RIGHT == key) {
playerShip.setDirection(Direction.RIGHT);
}
if (Key.DOWN == key) {
fireRocket();
}
if (Key.UP == key) {
fireBullet();
}
}
@Override
public void onKeyReleased(Key key) {
if (Key.LEFT == key && playerShip.getDirection() == Direction.LEFT) {
playerShip.setDirection(Direction.UP);
}
if (Key.RIGHT == key && playerShip.getDirection() == Direction.RIGHT) {
playerShip.setDirection(Direction.UP);
}
}
@Override
public void setCellValueEx(int x, int y, Color color, String value) {
if (x > WIDTH - 1 || x < 0 || y < 0 || y > HEIGHT - 1) {
return;
}
super.setCellValueEx(x, y, color, value);
}
public void menu() {
LEVEL = 1;
InMenu = true;
InPause = false;
Playbutton = new PlayButton();
blackFone();
createStars();
for (Star star : stars) {
star.draw(this);
}
Playbutton.draw(this);
showMessageDialog(Color.BLACK, "Версия " + VERSION +
"\n -Цель игры – уничтожить все вражеские корабли, при этом самому не погибнуть! " +
"\n -Управление:" +
"\n ← - влево, → - вправо, ↑ - стрельба, ↓ - ракета, пробел - рестарт" +
" (если погибли\\победили), ЛКМ - взаимодействие с кнопками.",
Color.YELLOW, 10);
}
public void printNums(int num, int x, int y) {
switch (num) {
case 0:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM0, ShapeMatrix.NUM0);
NumsAndText.draw(this);
break;
case 1:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM1, ShapeMatrix.NUM1);
NumsAndText.draw(this);
break;
case 2:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM2, ShapeMatrix.NUM2);
NumsAndText.draw(this);
break;
case 3:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM3, ShapeMatrix.NUM3);
NumsAndText.draw(this);
break;
case 4:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM4, ShapeMatrix.NUM4);
NumsAndText.draw(this);
break;
case 5:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM5, ShapeMatrix.NUM5);
NumsAndText.draw(this);
break;
case 6:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM6, ShapeMatrix.NUM6);
NumsAndText.draw(this);
break;
case 7:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM7, ShapeMatrix.NUM7);
NumsAndText.draw(this);
break;
case 8:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM8, ShapeMatrix.NUM8);
NumsAndText.draw(this);
break;
case 9:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM9, ShapeMatrix.NUM9);
NumsAndText.draw(this);
break;
case 10:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM1, ShapeMatrix.NUM1);
NumsAndText.draw(this);
printNums(0, x + 6, y);
break;
case 11:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM1, ShapeMatrix.NUM1);
NumsAndText.draw(this);
printNums(1, x + 6, y);
break;
case 12:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM1, ShapeMatrix.NUM1);
NumsAndText.draw(this);
printNums(2, x + 6, y);
break;
case 13:
NumsAndText = new Sprite(x, y, ShapeMatrix.NUM1, ShapeMatrix.NUM1);
NumsAndText.draw(this);
printNums(3, x + 6, y);
break;
default:
}
}
public void createGame() {
InMenu = false;
InPause = false;
isGameStopped = false;
if (LEVEL == 1) {
PlayerShip.HP = 6;
}
enemyFleet = new EnemyFleet();
enemyBullets = new ArrayList<>();
playerShip = new PlayerShip();
playerBullets = new ArrayList<>();
playerRockets = new ArrayList<>();
planet = new Planet();
Pausebutton = new PauseButton();
Menubutton = new MenuButton();
createStars();
drawScene();
setTurnTimer(TIMER);
}
public void drawAll() {
planet.draw(this);
enemyFleet.draw(this);
playerShip.draw(this);
Pausebutton.draw(this);
for (Bullet bullet : enemyBullets) {
bullet.draw(this);
}
for (Bullet bullet : playerBullets) {
bullet.draw(this);
}
for (Bullet bullet : playerRockets) {
bullet.draw(this);
}
for (int x = 0; x < WIDTH; x++) {
FoneLine = new Sprite(x, 89, ShapeMatrix.FONE_LINE, ShapeMatrix.FONE_LINE);
FoneLine.draw(this);
}
}
public void drawText() {
if (PlayerShip.HP == 6) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP6, ShapeMatrix.PLAYER_HP6);
HpSprite.draw(this);
}
if (PlayerShip.HP == 5) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP5, ShapeMatrix.PLAYER_HP5);
HpSprite.draw(this);
}
if (PlayerShip.HP == 4) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP4, ShapeMatrix.PLAYER_HP4);
HpSprite.draw(this);
}
if (PlayerShip.HP == 3) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP3, ShapeMatrix.PLAYER_HP3);
HpSprite.draw(this);
}
if (PlayerShip.HP == 2) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP2, ShapeMatrix.PLAYER_HP2);
HpSprite.draw(this);
}
if (PlayerShip.HP == 1) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP1, ShapeMatrix.PLAYER_HP1);
HpSprite.draw(this);
}
if (PlayerShip.HP == 0) {
HpSprite = new Sprite(1, 90, ShapeMatrix.PLAYER_HP0, ShapeMatrix.PLAYER_HP0);
HpSprite.draw(this);
}
NumsAndText = new Sprite(37, 91, ShapeMatrix.LV, ShapeMatrix.LV);
NumsAndText.draw(this);
printNums(LEVEL, 54, 90);
}
private void drawScene() {
drawField();
drawAll();
drawText();
for (int i = 0; i < PlayerRocketsMax; i++) {
RocketSprite = new Sprite(90 - 6 * i, 90, ShapeMatrix.ROCKET_GRAY);
RocketSprite.draw(this);
}
for (int i = 0; i < PlayerRocketsMax - playerRockets.size(); i++) {
RocketSprite = new Sprite(90 - 6 * i, 90, ShapeMatrix.ROCKET);
RocketSprite.draw(this);
}
}
public void blackFone() {
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
setCellValueEx(x, y, Color.BLACK, "");
}
}
}
private void drawField() {
blackFone();
for (Star star : stars) {
star.draw(this);
}
}
private void createStars() {
stars = new ArrayList<>();
for (int i = 0; i < 15; i++) {
int x = getRandomNumber(WIDTH);
int y = getRandomNumber(HEIGHT);
stars.add(new Star(x, y));
}
}
private void moveSpaceObjects() {
enemyFleet.move();
playerShip.move();
for (Bullet enemyBullet : enemyBullets) {
enemyBullet.move();
}
for (Bullet bullet : playerBullets) {
bullet.move();
}
for (Bullet bullet : playerRockets) {
bullet.move();
}
}
private void removeDeadBullets() {
for (Bullet bullet : new ArrayList<>(enemyBullets)) {
if (!bullet.isAlive || bullet.y >= HEIGHT - 1) {
enemyBullets.remove(bullet);
}
}
for (Bullet bullet : new ArrayList<>(playerBullets)) {
bullet.verifyHit(enemyBullets);
if (!bullet.isAlive || bullet.y + bullet.height < 0) {
playerBullets.remove(bullet);
}
}
for (Bullet bullet : new ArrayList<>(playerRockets)) {
bullet.verifyHit(enemyBullets);
if (!bullet.isAlive || bullet.y + bullet.height < 0) {
playerRockets.remove(bullet);
}
}
}
private void check() {
playerShip.verifyHit(enemyBullets);
score += enemyFleet.verifyHit(playerBullets);
score += enemyFleet.verifyHit(playerRockets);
enemyFleet.deleteHiddenShips();
removeDeadBullets();
if (!playerShip.isAlive) {
stopGameWithDelay();
}
if (enemyFleet.getBottomBorder() >= playerShip.y) {
playerShip.kill();
}
if (enemyFleet.getShipsCount() == 0) {
playerShip.win();
stopGameWithDelay();
}
}
private void stopGame(boolean isWin) {
if (isWin) {
showMessageDialog(Color.NONE, "Мы победили! Поставьте лайк игре!", Color.GREEN, 10);
LEVEL++;
} else {
LEVEL = 1;
WinAndLossText = new Sprite(40, 40, ShapeMatrix.GAME_OWER_TEXT);
WinAndLossText.draw(this);
}
stopTurnTimer();
isGameStopped = true;
}
private void stopGameWithDelay() {
animationsCount++;
if (animationsCount >= 10) {
stopGame(playerShip.isAlive);
}
}
}
Код работает исправно.