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();
         }
     }
 }
Beispiel #2
0
 private void RemoveUnidirectional(Cell other)
 {
     _neighbors.Remove(other);
 }
Beispiel #3
0
 private Cell AddUnidirectional(Cell other)
 {
     _neighbors.Add(other);
     return this;
 }
Beispiel #4
0
 public void RemoveNeighbor(Cell other)
 {
     RemoveUnidirectional(other);
     other.RemoveUnidirectional(this);
 }
Beispiel #5
0
 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;
 }
Beispiel #8
0
 private Cell AddLiveNeighbors(Cell cell, int numLiveNeighbors)
 {
     for (int i = 0; i < numLiveNeighbors; i++)
     {
         cell.AddNeighbor(Cell.MakeLive());
     }
     return cell;
 }