Помогите, пожалуйста. Что не так-то? Я прохожусь по листу forech, и проверяю если у объекта cell не советует хотя бы 1 из переданных координат, то я создаю новый объект и добавляю его в массив.Но, не проходит с комментарием: Убедись, что в при вызове метода onMouseLeftClick(int, int) переданные координаты добавляются в список cells.
-Та я убедился, как бы...или что я делаю не так?
package com.javarush.games.minigames.mini12;
import com.javarush.engine.cell.Color;
import com.javarush.engine.cell.Game;
import java.util.ArrayList;
import java.util.List;
/*
Работаем со списком координат
*/
public class FillGame extends Game {
private final List<Cell> cells = new ArrayList<>();
@Override
public void initialize() {
setScreenSize(10, 10);
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
setCellColor(x, y, Color.WHITE);
}
}
}
@Override
public void onMouseLeftClick(int x, int y) {
setCellColor(x, y, Color.ORANGE);
for (Cell cell : cells) {
if (cell.getX() != x ||
cell.getY() != y) cells.add(new Cell(x, y));
}
}
@Override
public void onMouseRightClick(int x, int y) {
setCellColor(x, y, Color.WHITE);
for (Cell cell :
cells) {
if (cell.getX() == x && cell.getY() == y) cells.remove(cell);
}
}
}
package com.javarush.games.minigames.mini12;
import java.util.Objects;
public class Cell {
private int x;
private int y;
public Cell(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Cell cell = (Cell) o;
return x == cell.x && y == cell.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}