Esempio n. 1
0
 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();
         }
     }
 }
Esempio n. 2
0
 private void RemoveUnidirectional(Cell other)
 {
     _neighbors.Remove(other);
 }
Esempio n. 3
0
 private Cell AddUnidirectional(Cell other)
 {
     _neighbors.Add(other);
     return this;
 }
Esempio n. 4
0
 public void RemoveNeighbor(Cell other)
 {
     RemoveUnidirectional(other);
     other.RemoveUnidirectional(this);
 }
Esempio n. 5
0
 public void AddNeighbor(Cell other)
 {
     AddUnidirectional(other);
     other.AddUnidirectional(this);
 }
Esempio n. 6
0
 public void Test()
 {
     Cell c = new Cell();
     Assert.AreEqual(c.Alive, false);
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 private Cell AddLiveNeighbors(Cell cell, int numLiveNeighbors)
 {
     for (int i = 0; i < numLiveNeighbors; i++)
     {
         cell.AddNeighbor(Cell.MakeLive());
     }
     return cell;
 }