Пример #1
0
        private void ValidateGrid(Grid grid)
        {
            int columnCount = grid.Rows.Max(r => r.Cells.Count);
            if (grid.Rows.Any(r => r.Cells.Count != columnCount))
                throw new ArgumentException("Template column numbers are not consistent. i.e. the number of columns are not the same in each row.");

            if (columnCount <= 1 || grid.Rows.Count <= 1)
                throw new ArgumentException("Template dimensions must be larger than one.", "template");
        }
Пример #2
0
        private IGameOfLifeGrid ConvertSerializedGridToGameGrid(Grid grid)
        {
            int columnCount = grid.Rows.Max(r => r.Cells.Count);
            GameOfLifeGrid g = new GameOfLifeGrid(columnCount, grid.Rows.Count);

            for (int rowIndex = 0; rowIndex < grid.Rows.Count; rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < grid.Rows[rowIndex].Cells.Count; columnIndex++)
                {
                    g[rowIndex, columnIndex] = new Cell(grid.Rows[rowIndex].Cells[columnIndex].On ? CellState.Live : CellState.Dead, columnIndex, rowIndex);
                }
            }

            return g;
        }