Esempio n. 1
0
        private static Cell[][] GetCells(int height, int width)
        {
            string[] lines = new string[height];

            StringBuilder line = new StringBuilder(width, width);

            for (int i = 0; i < height; i++)
            {
                line.Clear();
                for (int j = 0; j < width; j++)
                {
                    char input = Console.ReadKey().KeyChar;

                    if (!CellUtilities.IsCell(input))
                    {
                        Console.WriteLine();
                        return(null);
                    }
                    line.Append(input);
                }
                Console.WriteLine();

                lines[i] = line.ToString();
            }

            return(Template.GetCells(height, width, lines));
        }
Esempio n. 2
0
        private static void NewGame(IReadOnlyList <string> templates)
        {
            Console.WriteLine("--- New Game ---");
            Console.WriteLine("Templates:");
            for (int i = 0; i < templates.Count; i++)
            {
                Console.WriteLine($"{i + 1}. {templates[i]}");
            }
            Console.WriteLine();

            Console.Write("Select a template: ");
            string input = Console.ReadLine();

            Console.WriteLine();

            int option;

            if (!int.TryParse(input, out option) || option < 1 || option > templates.Count)
            {
                Console.WriteLine("Invalid input.");
                return;
            }

            string   name     = templates[option - 1];
            Template template = Template.LoadTemplate(name);

            Console.WriteLine("Template");
            Console.WriteLine($"Name  : {template.Name}");
            Console.WriteLine($"Height: {template.Height}");
            Console.WriteLine($"Width : {template.Width}");
            Console.WriteLine(CellUtilities.ToString(template.Cells));

            NewGame(template);
        }
Esempio n. 3
0
        public static Cell[][] GetCells(int height, int width, string[] lines)
        {
            if (height < 1 || width < 1 ||
                lines == null || lines.Length != height || lines.Any(x => x.Length != width))
            {
                throw new ArgumentException();
            }

            Cell[][] cells = new Cell[height][];
            for (int y = 0; y < height; y++)
            {
                cells[y] = new Cell[width];
                for (int x = 0; x < width; x++)
                {
                    cells[y][x] = CellUtilities.GetCell(lines[y][x]);
                }
            }

            return(cells);
        }
Esempio n. 4
0
 public override string ToString()
 {
     return(CellUtilities.ToString(Cells));
 }