Example #1
0
        public GameOfLife(int width, int height)
        {
            ValidateGridDimension(width);
            ValidateGridDimension(height);

            this.grid = new GameOfLifeGrid(width, height);
            this.Generation = 1;
            this.InitializeCells();
        }
Example #2
0
        public string Serialize(IGameOfLifeGrid grid)
        {
            Grid g = Grid.NewGrid();

            for (int rowIndex = 0; rowIndex < grid.Size.Height; rowIndex++)
            {
                GridRow row = GridRow.Empty;

                for (int columnIndex = 0; columnIndex < grid.Size.Width; columnIndex++)
                {
                    row.Cells.Add(new GridCell { On = grid.GetCellState(rowIndex, columnIndex) == CellState.Live });
                }

                g.Rows.Add(row);
            }

            return JsonConvert.SerializeObject(g);
        }
Example #3
0
 public void InitializeFromTemplate(string template)
 {
     this.grid = new GameOfLifeSerializer().Deserialize(template);
     this.Generation = 1;
 }