private static void NewGame(ITemplate template) { Console.Write($"Enter game height (must be at least {template.Height}): "); string input = Console.ReadLine(); Console.WriteLine(); int height; if (!int.TryParse(input, out height) || height < 1 || height < template.Height) { Console.WriteLine("Invalid input."); return; } Console.Write($"Enter game width (must be at least {template.Width}): "); input = Console.ReadLine(); Console.WriteLine(); int width; if (!int.TryParse(input, out width) || width < 1 || width < template.Width) { Console.WriteLine("Invalid input."); return; } Console.Write($"Enter template x coordinate (cannot be more than {width - template.Width}): "); input = Console.ReadLine(); Console.WriteLine(); int templateX; if (!int.TryParse(input, out templateX) || templateX < 0 || templateX > width - template.Width) { Console.WriteLine("Invalid input."); return; } Console.Write($"Enter template y coordinate (cannot be more than {height - template.Height}): "); input = Console.ReadLine(); Console.WriteLine(); int templateY; if (!int.TryParse(input, out templateY) || templateY < 0 || templateY > height - template.Height) { Console.WriteLine("Invalid input."); return; } GameOfLife gameOfLife = new GameOfLife(height, width); gameOfLife.PlayGame(template, templateX, templateY); }
// ReSharper disable once SuggestBaseTypeForParameter private static void CommandLineArguments(string[] args) { // <game-height> <game-width> <template-name> <template-x> <template-y> int argsIndex = 0; int height; if (!int.TryParse(args[argsIndex++], out height) || height < 1) { Console.WriteLine("Game height invalid."); return; } int width; if (!int.TryParse(args[argsIndex++], out width) || width < 1) { Console.WriteLine("Game width invalid."); } Template template = Template.LoadTemplate(args[argsIndex++]); if (template == null) { Console.WriteLine("Template not found."); return; } int templateX; if (!int.TryParse(args[argsIndex++], out templateX) || templateX <0 || templateX> width - template.Width) { Console.WriteLine("Template x coordinate invalid."); return; } int templateY; if (!int.TryParse(args[argsIndex], out templateY) || templateY <0 || templateY> height - template.Height) { Console.WriteLine("Template y coordinate invalid."); return; } GameOfLife gameOfLife = new GameOfLife(height, width); gameOfLife.PlayGame(template, templateX, templateY); }