Esempio n. 1
0
 public void CheckDimentions(Generation nextGeneration)
 {
     _dimentions.RowStart = _checkDimension.CheckFieldRows(nextGeneration, 0, 1);
     _dimentions.RowEnd = _checkDimension.CheckFieldRows(nextGeneration, nextGeneration.DimensionX - 1, -1);
     _dimentions.ColumnStart = _checkDimension.CheckFieldColumns(nextGeneration, 0, 1);
     _dimentions.ColumnEnd = _checkDimension.CheckFieldColumns(nextGeneration, nextGeneration.DimensionY - 1, -1);
 }
Esempio n. 2
0
 public GameLife(int dimensionX, int dimensionY, int increase)
 {
     _fillGeneration = new GenerationalFill();
     _printResult = new GenerationalPrint();
     _currentGeneration = new Generation();
     _currentGeneration.DimensionX = dimensionX;
     _currentGeneration.DimensionY = dimensionY;
     _currentGeneration.Increase = increase;
     _consoleStyle = new ConsoleStyle();
 }
Esempio n. 3
0
 public int CheckFieldRows(Generation nextGeneration, int row, int step)
 {
     for (int i = row; i < nextGeneration.DimensionX && i >= 0; i += step)
     {
         for (int j = 0; j < nextGeneration.DimensionY; j++)
         {
             if (nextGeneration.ReadValueXY(i, j) == 1) return i;
         }
     }
     return -1;
 }
Esempio n. 4
0
 public int CheckFieldColumns(Generation nextGeneration, int column, int step)
 {
     for (int j = column; j < nextGeneration.DimensionY && j >= 0; j += step)
     {
         for (int i = 0; i < nextGeneration.DimensionX; i++)
         {
             if (nextGeneration.ReadValueXY(i, j) == 1) return j;
         }
     }
     return -1;
 }
Esempio n. 5
0
 public void MakeFilling(Generation currentGeneration)
 {
     Random random = new Random();
     for (int row = 0; row < currentGeneration.DimensionX; row++)
     {
         Region listRow = new Region();
         for (int column = 0; column < currentGeneration.DimensionY; column++)
         {
             listRow.Add(random.Next(0, 2));
         }
         currentGeneration.WriteRow(listRow);
     }
 }
Esempio n. 6
0
 public void PrintResult(Generation currentGeneration)
 {
     for (int row = 0; row < currentGeneration.DimensionX; row++)
     {
         for (int column = 0; column < currentGeneration.DimensionY; column++)
         {
             if (currentGeneration.ReadValueXY(row, column) != 0)
             {
                 currentGeneration.WriteValueXY(row, column, 1);
                 Console.Write((char)currentGeneration.ReadValueXY(row, column));
             }
             else { Console.Write(" "); }
         }
         Console.WriteLine();
     }
 }
Esempio n. 7
0
 public Generation RewriteGeneration(Generation currentGeneration, Generation nextGeneration, Dimention dimentions)
 {
     currentGeneration.DimensionX = dimentions.RowEnd - dimentions.RowStart + 1;
     currentGeneration.DimensionY = dimentions.ColumnEnd - dimentions.ColumnStart + 1;
     currentGeneration.ClearContent();
     for (int row = 0; row < currentGeneration.DimensionX; row++)
     {
         Region listRow = new Region();
         for (int column = 0; column < currentGeneration.DimensionY; column++)
         {
             listRow.Add(nextGeneration.ReadValueXY(row + dimentions.RowStart, column + dimentions.ColumnStart));
         }
         currentGeneration.WriteRow(listRow);
     }
     return currentGeneration;
 }
Esempio n. 8
0
        public Generation RefillGeneration(Generation currentGeneration)
        {
            Generation nextGeneration = new Generation();
            nextGeneration.DimensionX = currentGeneration.DimensionX + currentGeneration.Increase * 2;
            nextGeneration.DimensionY = currentGeneration.DimensionY + currentGeneration.Increase * 2;

            for (int row = 0; row < nextGeneration.DimensionX; row++)
            {
                Region listRow = new Region();
                for (int column = 0; column < nextGeneration.DimensionY; column++)
                {
                    CheckFieldModification check = new CheckFieldModification(currentGeneration, row - currentGeneration.Increase, column - currentGeneration.Increase);
                    listRow.Add(check.CheckStatusForNeighbours());
                    check.Dispose();
                }
                nextGeneration.WriteRow(listRow);
            }
            if (_checkDimension.CheckFieldRows(nextGeneration, 0, 1) == -1) { currentGeneration.ClearContent(); return currentGeneration; }
            _dimentions = new Dimention(currentGeneration.DimensionX, currentGeneration.DimensionY);
            if (currentGeneration.Increase > 0) CheckDimentions(nextGeneration);
            return _makeChange.RewriteGeneration(currentGeneration, nextGeneration, _dimentions);
        }
Esempio n. 9
0
 public void PrintField(Generation currentGeneration)
 {
 }
Esempio n. 10
0
 public CheckFieldModification(Generation currentGeneration, int row, int column)
 {
     _currentGeneration = currentGeneration;
     _row = row;
     _column = column;
 }
Esempio n. 11
0
 public CheckFieldModification(Generation currentGeneration, int row, int column)
 {
     _currentGeneration = currentGeneration;
     _row    = row;
     _column = column;
 }