public GameOfLife(int width, int height) { ValidateGridDimension(width); ValidateGridDimension(height); this.grid = new GameOfLifeGrid(width, height); this.Generation = 1; this.InitializeCells(); }
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); }
public void InitializeFromTemplate(string template) { this.grid = new GameOfLifeSerializer().Deserialize(template); this.Generation = 1; }