static void Main(string[] args) { Console.WriteLine("Welcome to game of life"); Console.WriteLine("Set the number of iterations you want"); int iterationsCount = Convert.ToInt32(Console.ReadLine()); // Mainitaing two grids Grid grid = new Grid(); Grid backUpGrid = new Grid(); //Generating a random grid view var cells = grid.GetRandomValuesCells(); //Display the rand grid Console.WriteLine(); Console.WriteLine("We have created a random grid and here it is: "); grid.DisplayGrid(cells); //Display Game of life in every step if (iterationsCount > 0) { Console.WriteLine(); Console.WriteLine("Level 0 Reperesentaion: "); backUpGrid.Cells = grid.SetGridNextLevelState(grid.Cells); grid.DisplayGrid(backUpGrid.Cells); } for (int i = 1; i < iterationsCount; i++) { Console.WriteLine(); Console.WriteLine("Level " + i + " Representation: "); backUpGrid.Cells = grid.SetGridNextLevelState(backUpGrid.Cells); grid.DisplayGrid(backUpGrid.Cells); } }
static void Main(string[] args) { bool repeat = true; Console.Write("Welcome to the game of life.\nHow many lines high would you like to make your grid?: "); string heightString = Console.ReadLine(); int height; bool error = false; if (!int.TryParse(heightString, out height)) { error = true; } while (repeat) { //height parsed correctly if (!error) { Console.WriteLine("\nCreate your grid line by line.\nUse X for alive cells, all other cells will be considered dead.\nEach row will be padded to the length of the longest row with empty cells.\n\n"); List <string> lines = new List <string>(); for (var i = 0; i < height; i++) { string line = Console.ReadLine(); lines.Add(line); } bool[,] testboolarray = new bool[2, 2]; Grid grid = new Grid(ConvertToGridArray(lines)); //Grid testgrid = new Grid(testboolarray); Console.Clear(); Console.WriteLine(grid.DisplayGrid()); grid.UpdateState(); Console.WriteLine(grid.DisplayGrid()); Console.ReadLine(); } } }