Bien le bonjour!
Quelqu'un peut m'éclairer sur mon erreur ? Je n'arrive pas a faire rouler la méthode countMineNeighbors (). Ca compile bien mais la task ne veut pas se valider...
Merci d'avance :)
package com.codegym.games.minesweeper;
import com.codegym.engine.cell.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class MinesweeperGame extends Game {
private static final int SIDE = 9;
private GameObject[][] gameField = new GameObject[SIDE][SIDE];
private int countMinesOnField;
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 ? true : false;
if (isMine) {
countMinesOnField++;
}
gameField[y][x] = new GameObject (x, y, isMine);
setCellColor (x, y, Color.ORANGE);
}
}
countMineNeighbors();
}
private ArrayList<GameObject> getNeighbors (GameObject gameObject) {
ArrayList <GameObject> neighbors = 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 (x <0 || x > SIDE) {
continue;
}
if (y < 0 || y > SIDE){
continue;
}
if (x == gameObject.x && y == gameObject.y) {
continue;
}
neighbors.add(gameField[y][x]);
}
}
return neighbors;
}
private void countMineNeighbors () {
for (int y = 0; y < SIDE; y++){
for(int x=0; x < SIDE; x++) {
if (!gameField[y][x].isMine) {
int count = 0;
for (GameObject o : getNeighbors(gameField[y][x])){
if (o.isMine){
count++;
}
}
gameField[y][x].countMineNeighbors = count;
}
}
}
}
}