public class Grid
{
private int height, width;
private Cell[][] grid;
private Mode mode;
public Grid(int size)
{
this(size, Mode.ONE);
}
public Grid(int size, Mode mode)
{
this(size, size, mode);
}
public Grid(int height, int width, Mode mode)
{
this.height = height;
this.width = width;
grid = new Cell[height][width];
Cell.resetId();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
grid[i][j] = new Cell();
}
}
this.mode = mode;
}
public Cell get(int x, int y)
{
return grid[x][y];
}
public Point[] getNeighbours(Point p)
{
Point[] result;
int counter = 0;
if (mode == Mode.ONE)
{
result = new Point[4];
for (int i = 0; i < 2; i++)
{
result[counter++] = new Point(p.getX() + i, p.getY() + i - 1);
result[counter++] = new Point(p.getX() - i, p.getY() - i + 1);
}
} else
{
result = new Point[8];
for (int i = -1; i < 2; i++)
{
for (int j = -1; j < 2; j++)
{
if (i == j && i == 0)
continue;
result[counter++] = new Point(p.getX() + i, p.getY() + j);
}
}
}
return result;
}
}