Здравствуйте, не показывает счет, не моя программа, не правильное решение на сайте. Есть возможность исправить?
package com.javarush.games.minesweeper;
import com.javarush.engine.cell.Color;
import com.javarush.engine.cell.Game;
import java.util.ArrayList;
import java.util.List;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
private static final String MINE = "\uD83D\uDCA3";
private static final String FLAG = "\uD83D\uDEA9";
private int countFlags;
private boolean isGameStopped = false;
private int countClosedTiles = SIDE * SIDE;
private int score;
@Override
public void initialize() {
setScreenSize(SIDE, SIDE);
createGame();
}
private void createGame() {
for (int y = 0; y < SIDE; y++) {
for (int x = 0; x < SIDE; x++) {
boolean isMine = getRandomNumber(10) < 1;
if (isMine) {
countMinesOnField++;
}
gameField[y][x] = new GameObject(x, y, isMine);
setCellColor(x, y, Color.ORANGE);
setCellValue(x, y , "");
}
}
countMineNeighbors();
countFlags = countMinesOnField;
}
private List<GameObject> getNeighbors(GameObject gameObject) {
List<GameObject> result = new ArrayList<>();
for (int y = gameObject.y - 1; y <= gameObject.y + 1; y++) {
for (int x = gameObject.x - 1; x <= gameObject.x + 1; x++) {
if (y < 0 || y >= SIDE) {
continue;
}
if (x < 0 || x >= SIDE) {
continue;
}
if (gameField[y][x] == gameObject) {
continue;
}
result.add(gameField[y][x]);
}
}
return result;
}
private void countMineNeighbors(){
for (int y = 0; y < SIDE; y++) {
for (int x = 0; x < SIDE; x++) {
if (gameField[x][y].isMine)
continue;
List<GameObject> list= getNeighbors(gameField[x][y]);
gameField[x][y].countMineNeighbors = 0;
for (int i =0; i < list.size(); i++)
if (list.get(i).isMine){
gameField[x][y].countMineNeighbors++;
}
}
}
}
public void onMouseLeftClick(int x, int y){
if (isGameStopped){
restart();
return;
}
openTile(x, y);
}
private void openTile(int x, int y){
GameObject gameObject = gameField[x][y];
if (gameObject.isOpen)
return;
if (gameObject.isFlag)
return;
if (isGameStopped)
return;
if (gameObject.isMine){
setCellValueEx(gameObject.y, gameObject.x, Color.RED, MINE);
gameOver();
return;
}
else if (gameObject.countMineNeighbors == 0) {
gameObject.isOpen = true;
score = score + 5;
setScore(score);
countClosedTiles--;
setCellValue(gameObject.y, gameObject.x, "");
setCellColor(x, y, Color.GREEN);
List<GameObject> list = getNeighbors(gameObject);
for (int i = 0; i < list.size(); i++){
openTile(list.get(i).y, list.get(i).x);
}
}
else{
setCellNumber(x, y, gameObject.countMineNeighbors);
gameObject.isOpen = true;
score = score + 5;
setScore(score);
countClosedTiles--;
}
setCellColor(x, y, Color.GREEN);
if (countClosedTiles == countMinesOnField)
win();
}
private void markTile(int x, int y){
GameObject gameObject= gameField[x][y];
if (isGameStopped)
return;
if (gameObject.isOpen)
return;
if (countFlags == 0 && (!gameObject.isFlag))
return;
if (gameObject.isFlag){
gameObject.isFlag = false;
countFlags++;
setCellValue(x, y, "");
setCellColor(x, y, Color.ORANGE);
}
else{
gameObject.isFlag = true;
countFlags--;
setCellValue(x, y, FLAG);
setCellColor(x, y, Color.YELLOW);
}
}
public void onMouseRightClick(int x, int y){
markTile(x, y);
}
private void gameOver(){
isGameStopped = true;
showMessageDialog(Color.NONE, "Game over!", Color.RED, 75);
}
private void win(){
isGameStopped = true;
showMessageDialog(Color.RED, "YOU WIN!!!", Color.GREEN, 75);
}
private void restart(){
isGameStopped = false;
countMinesOnField = 0;
score =0;
setScore(score);
countClosedTiles = SIDE * SIDE;
createGame();
}
}