Пример #1
0
        static void Main(string[] args)
        {
            Console.Write("Enter the number of discs per peg (2 - 18): ");
            var pegSize = int.Parse(Console.ReadLine() ?? "3");

            Console.WriteLine("Choose the solver to run: ");
            var solvers      = FindAllSolvers().ToArray();
            var solverNumber = 0;

            foreach (var solverType in solvers)
            {
                solverNumber++;
                Console.WriteLine($"{solverNumber}: {solverType.FullName}");
            }

            solverNumber = int.Parse(Console.ReadLine() ?? "1");

            var game   = new TowerGame(pegSize);
            var drawer = new ConsoleDrawer();
            var solver = (ISolveTowers)Activator.CreateInstance(solvers[solverNumber - 1]);

            drawer.Draw(game);

            var moves = RunTowerThroughTheSolver(solver, game, drawer);

            if (game.IsGameOver())
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The Tower has been SOLVED!!!");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("The Tower has NOT been solved. :(");
            }

            Console.ForegroundColor = ConsoleColor.White;

            var numberOfInvalidMoves = moves.Count(m => !m.Valid);

            Console.WriteLine($"Number of moves: {moves.Count}. Invalid Moves: {numberOfInvalidMoves}.");
            Console.WriteLine("Print the move history? (Y/N)");
            var printAnswer = Console.ReadLine()?.ToUpper() ?? "";

            if (printAnswer == "Y")
            {
                PrintMoveLogToConsole(moves);
            }
        }
Пример #2
0
        static void InitConsoleDrawer(ConsoleMap map, Vector2Int scale, int spacing, Vector2Int start, Vector2Int stop, int index)
        {
            ConsoleColorLayer backgroundLayer = map.GetColorLayer();
            ConsoleTextLayer  textLayer       = new ConsoleTextLayer(backgroundLayer.Width, backgroundLayer.Height);

            int x      = (map.Width * scale.X + spacing) * index;
            var drawer = new ConsoleDrawer(x, 0, scale, backgroundLayer, textLayer);

            drawer.SetTextCell(start.X, start.Y, "S");
            drawer.SetTextCell(stop.X, stop.Y, "E");

            Console.CursorTop = map.Height;
            drawer.Draw();

            _consoleDrawers[index] = drawer;
        }
Пример #3
0
        private static void TestInputOutputCommunication()
        {
            var display = new ConsoleDisplay("Some App", 90, 25);
            var reader  = new ConsoleReader();
            var drawer  = new ConsoleDrawer();

            while (true)
            {
                if (reader.HasPressedKey)
                {
                    var key = reader.ReadKey();
                    switch (key)
                    {
                    case KeyType.A:
                    case KeyType.LeftArrow:
                        drawer.MoveAt(drawer.CurrentX - 1, drawer.CurrentY);
                        break;

                    case KeyType.W:
                    case KeyType.UpArrow:
                        drawer.MoveAt(drawer.CurrentX, drawer.CurrentY - 1);
                        drawer.Draw(reader.ReadKey().ToString(), ColorType.Blue, ColorType.White);
                        break;

                    case KeyType.S:
                    case KeyType.DownArrow:
                        drawer.MoveAt(drawer.CurrentX, drawer.CurrentY + 1);
                        break;

                    case KeyType.D:
                    case KeyType.RightArrow:
                        drawer.MoveAt(drawer.CurrentX + 1, drawer.CurrentY);
                        break;

                    case KeyType.Escape:
                        display.SetBackDefaultScreenSettings();
                        Environment.Exit(0);
                        break;
                    }
                }
            }
        }