public Game(int x, int y) { Field = new Cell[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { Field[i,j] = new Cell(); } } }
private void RemoveUnidirectional(Cell other) { _neighbors.Remove(other); }
private Cell AddUnidirectional(Cell other) { _neighbors.Add(other); return this; }
public void RemoveNeighbor(Cell other) { RemoveUnidirectional(other); other.RemoveUnidirectional(this); }
public void AddNeighbor(Cell other) { AddUnidirectional(other); other.AddUnidirectional(this); }
public void Test() { Cell c = new Cell(); Assert.AreEqual(c.Alive, false); }
public void Step() { var x = Field.GetLength(0); var y = Field.GetLength(1); Cell[,] newField = new Cell[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { newField[i,j] = new Cell(); } } for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { var count = this.countAliveAdjacent(i, j); newField[i, j].Alive = count == 2 ? Field[i, j].Alive : count == 3 ? true : false; } } this.Field = newField; }
private Cell AddLiveNeighbors(Cell cell, int numLiveNeighbors) { for (int i = 0; i < numLiveNeighbors; i++) { cell.AddNeighbor(Cell.MakeLive()); } return cell; }