public Cell[] getLivingNeighboors() { int i = -1; Cell[] livingNeighboors = new Cell[getLivingNeighboorsCount()]; foreach(Cell neighboor in getNeighboors()) { if(neighboor.getCellState()) { livingNeighboors[++i] = neighboor; } } return livingNeighboors; }
public Cell[] getNeighboors() { Cell[] neighboors = new Cell[8]; neighboors[0] = pole.getCell(x, y - 10); neighboors[1] = pole.getCell(x + 10, y - 10); neighboors[2] = pole.getCell(x + 10, y); neighboors[3] = pole.getCell(x + 10, y + 10); neighboors[4] = pole.getCell(x, y + 10); neighboors[5] = pole.getCell(x - 10, y + 10); neighboors[6] = pole.getCell(x - 10, y); neighboors[7] = pole.getCell(x - 10, y - 10); return neighboors; }
/// <summary> /// Ининциализация элемента "Вселенная" /// </summary> /// <param name="heightCount">Количество строк</param> /// <param name="widthCount">Количестов ячеек в каждой строке</param> public Space(int heightCount, int widthCount) { if (heightCount < 0 || widthCount < 0) { throw new ArgumentException(); } HeightCount = heightCount; WidthCount = widthCount; Cells = new Cell[HeightCount * WidthCount]; for (var i = 0; i < heightCount * widthCount; i++) { Cells[i] = new Cell(); } }