91 строка не пускает валидатор!!!
package com.javarush.games.racer;
import com.javarush.engine.cell.*;
import com.javarush.games.racer.road.RoadManager;
public class RacerGame extends Game {
private boolean isGameStopped;
public final static int WIDTH = 64;
public final static int HEIGHT = 64;
public final static int CENTER_X = WIDTH / 2;
public final static int ROADSIDE_WIDTH = 14;
private ProgressBar progressBar;
private RoadMarking roadMarking;
private PlayerCar player;
private FinishLine finishLine;
private RoadManager roadManager;
private static final int RACE_GOAL_CARS_COUNT = 40;
private int score;
public static void main(String[] args) {
RacerGame game = new RacerGame();
game.initialize();
}
private void gameOver() {
isGameStopped=true;
stopTurnTimer();
showMessageDialog(Color.BLACK,"GAME OVER",Color.RED,10);
player.stop();
}
@Override
public void initialize() {
setScreenSize(WIDTH,HEIGHT);
showGrid(false);
createGame();
}
@Override
public void setCellColor(int x, int y, Color color) {
if((x >=0 && x <64) && (y >=0 && y<64))
super.setCellColor(x, y, color);
}
@Override
public void onKeyPress(Key key) {
if(key.equals(Key.LEFT))
player.setDirection(Direction.LEFT);
else if(key.equals(Key.RIGHT))
player.setDirection(Direction.RIGHT);
else if(key.equals(Key.SPACE) && isGameStopped)
createGame();
else if(key.equals(Key.UP))
player.speed*=2;
}
@Override
public void onKeyReleased(Key key) {
if((key.equals(Key.LEFT) && player.getDirection().equals(Direction.LEFT) ) || key.equals(Key.RIGHT) && player.getDirection().equals(Direction.RIGHT))
player.setDirection(Direction.NONE);
else if(key.equals(Key.UP))
player.speed = 1;
}
private void win() {
isGameStopped = true;
showMessageDialog(Color.BLACK,"YOU WON",Color.GREEN,30);
stopTurnTimer();
}
@Override
public void onTurn(int step) {
boolean condition = roadManager.checkCrush(player);
if (condition) {
gameOver();
drawScene();
return;
} else {
if (roadManager.getPassedCarsCount() >= RACE_GOAL_CARS_COUNT) {
finishLine.show();
}
if (finishLine.isCrossed(player)) {
win();
drawScene();
return;
}
moveAll();
roadManager.generateNewRoadObjects(this);
}
moveAll();
score-=5;
setScore(score);
drawScene();
progressBar.draw(this);
}
/*
public void onTurn(int step) {
score -=5;
setScore(score);
if(roadManager.checkCrush(player))
{
gameOver();
drawScene();
return;
}
if( finishLine.isCrossed(player)) {
win();
drawScene();
return;
}
if(roadManager.getPassedCarsCount() >= RACE_GOAL_CARS_COUNT)
finishLine.show();
moveAll();
roadManager.generateNewRoadObjects(this);
progressBar.draw(this);
drawScene();
}
*/
private void createGame() {
roadMarking= new RoadMarking();
player = new PlayerCar();
roadManager = new RoadManager();
isGameStopped=false;
finishLine = new FinishLine();
progressBar = new ProgressBar(RACE_GOAL_CARS_COUNT);
drawScene();
setTurnTimer(40);
score=3500;
}
private void drawScene() {
drawField();
progressBar.draw(this);
finishLine.draw(this);
roadMarking.draw(this);
player.draw(this);
roadManager.draw(this);
}
private void drawField() {
for(int x =0;x < WIDTH; x++) {
for(int y = 0;y < HEIGHT; y++) {
if( (x >= 0 && x < ROADSIDE_WIDTH) || (x >= WIDTH - ROADSIDE_WIDTH && x <= WIDTH) )
setCellColor(x,y,Color.YELLOW);
else if(x == CENTER_X)
setCellColor(CENTER_X,y,Color.WHITE);
else
setCellColor(x,y,Color.BLACK);
}
}
}
private void moveAll() {
roadMarking.move(player.speed);
player.move();
roadManager.move(player.speed);
finishLine.move(player.speed);
progressBar.move(roadManager.getPassedCarsCount());
}
}