Пример #1
0
        static void Main(string[] args)
        {
            var commandReader = new ConsoleCommandsReader();
            var drawer        = new ConsoleDrawer();

            using (new CommandHandler(commandReader, drawer))
            {
                commandReader.Start();
            }
        }
Пример #2
0
        public static void Start()
        {
            WorkStatus = ACTIVE;

            GetCurrentUser();
            InitCommands();

            ConsoleDrawer.PrintInitialInfo();
            StartGettingCommands();
        }
Пример #3
0
 public Field(Figure roadBorder, Figure mainCar, List <Figure> rivalCars)
 {
     this.RoadBorder = roadBorder;
     this.MainCar    = mainCar;
     this.RivalCars  = rivalCars;
     this.drawer     = new ConsoleDrawer();
     this.InitializeState();
     this.RoadBorder.InitializeState();
     this.MainCar.InitializeState();
     this.RivalCars[0].InitializeState();
     this.KeyboardHandler           = new KeyboardHandler();
     this.KeyboardHandler.KeyLeft  += this.OnKeyLeft;
     this.KeyboardHandler.KeyRight += this.OnKeyRight;
 }
Пример #4
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);
            }
        }
Пример #5
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;
        }
Пример #6
0
        private static void Main()
        {
            var consoleDrawer          = new ConsoleDrawer();
            var paintWithConsoleDrawer = new Paint(consoleDrawer);

            string filePath              = Directory.GetCurrentDirectory() + @"..\..\..\batman.txt";
            var    streamDrawer          = new StreamDrawer(filePath);
            var    paintWithStreamDrawer = new Paint(streamDrawer);

            int  drawingSize = int.Parse(Console.ReadLine());
            char drawingSymb = char.Parse(Console.ReadLine());

            paintWithConsoleDrawer.DrawBatman(drawingSize, drawingSymb);
            paintWithStreamDrawer.DrawBatman(drawingSize, drawingSymb);

            streamDrawer.CloseStream();
        }
Пример #7
0
        private static void Login()
        {
            while (true)
            {
                string email = GetData("email");
                string pass  = GetData("password");

                User user = DBWorker.GetExistingUser(email, pass);
                if (user != null)
                {
                    CurrentUser = user;
                    break;
                }
                else
                {
                    ConsoleDrawer.DrawMessage(new OperationStatusMessage("INCORRECT EMAIL OR PASSWORD!", "ERROR"));
                }
            }
        }
Пример #8
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;
                    }
                }
            }
        }
Пример #9
0
        private static void GetCurrentUser()
        {
            while (true)
            {
                string method = GetData("login or register?");

                if (method == "login")
                {
                    Login();
                    break;
                }
                else if (method == "register")
                {
                    Register();
                    break;
                }
                else
                {
                    ConsoleDrawer.DrawMessage(new OperationStatusMessage("INCORRECT DATA!", "ERROR"));
                }
            }
        }
Пример #10
0
        private static string GetVerifiedEmail()
        {
            string      email       = GetData("email");
            EmailSender emailSender = new EmailSender();

            while (true)
            {
                Console.WriteLine("Verification code has been sent to your email");
                emailSender.SendVerifyCode(email);
                string userCode = GetData("code");

                if (userCode == emailSender.VERIFY_CODE)
                {
                    ConsoleDrawer.DrawMessage(new OperationStatusMessage("EMAIL CONFRIMED SUCCESSFULLY", "SUCCESS"));
                    return(email);
                }
                else
                {
                    ConsoleDrawer.DrawMessage(new OperationStatusMessage("INCORRECT CODE!", "ERROR"));
                }
            }
        }
Пример #11
0
        static void Main(string[] args)
        {
            DrawerProvider.Drawer.InitField();

            var drawer = new ConsoleDrawer();

            generator     = new FigureGenerator(Field.Width / 2, 0);
            currentFigure = generator.GetNewFigure();
            SetTimer();

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    Monitor.Enter(_lockObject);
                    var result = HandleKey(currentFigure, key.Key);
                    ProcessResult(result, ref currentFigure);
                    Monitor.Exit(_lockObject);
                }
            }
        }
Пример #12
0
        private static void StartGettingCommands()
        {
            while (WorkStatus == ACTIVE)
            {
                string commandStr     = GetCommand();
                bool   commandIsFound = false;

                foreach (var command in Commands)
                {
                    if (commandStr == command.Name)
                    {
                        command.Execute();
                        ConsoleDrawer.PrintLastLog();
                        commandIsFound = true;
                    }
                }

                if (!commandIsFound)
                {
                    ConsoleDrawer.DrawMessage(new OperationStatusMessage("COMMAND NOT FOUND!", "ERROR"));
                }
            }
        }
Пример #13
0
 public Game(Map map)
 {
     _MAP = map;
     cd   = new ConsoleDrawer(_MAP);
 }
Пример #14
0
        private void StartGame(GameLevel gameLevel)
        {
            Console.Clear();
            Console.CursorVisible = false;
            this.score            = 0;
            this.drawer           = new ConsoleDrawer();
            this.drawer.DrawCountDown();
            this.stopwatch = new Stopwatch();
            this.stopwatch.Start();
            Field field = new Field(
                new RoadBorder(ConsoleColor.DarkGreen, '#'),
                new MainCar(this.MainCarColor, 'x'),
                new List <Figure>
            {
                new RivalCar(this.GenerateColor(), '*')
            });

            if (gameLevel == GameLevel.CanIPlayDaddy)
            {
                this.drawer.DrawGameLevel(field, "Can I play, Daddy?");
                this.speed = 150;
            }
            else if (gameLevel == GameLevel.BringEmOn)
            {
                this.drawer.DrawGameLevel(field, "Bring 'em on!");
                this.speed = 120;
            }
            else
            {
                this.drawer.DrawGameLevel(field, "I am Death incarnate!");
                this.speed = 30;
            }
            do
            {
                field.KeyboardHandler.QueryKeyboardHandler();
                TimeSpan timeSpan = this.stopwatch.Elapsed;
                Task.Run(() => { this.drawer.DrawTimeInGame(field, timeSpan); }).Wait();
                Task.Run(() => { this.drawer.DrawScore(field, this.score); }).Wait();
                Task.Run(() => { this.drawer.DrawFigure(field.RoadBorder); }).Wait();
                Thread.Sleep(this.speed);
                field.RoadBorder.Move(MoveDirection.Down);
                foreach (var rivalCar in new List <Figure>(field.RivalCars))
                {
                    rivalCar.Move(MoveDirection.Down);
                    this.drawer.DrawFigure(rivalCar, field);

                    Node highestRivalCarNode = rivalCar.nodes.OrderBy(node => node.Y).FirstOrDefault();
                    if (highestRivalCarNode != null)
                    {
                        if (highestRivalCarNode.Y == 4)
                        {
                            field.RivalCars.Add(new RivalCar(this.GenerateColor(), '*'));
                            field.RivalCars[field.RivalCars.Count - 1].InitializeState();
                            this.score += 10;
                            if (gameLevel == GameLevel.BringEmOn && this.score % 100 == 0)
                            {
                                this.speed -= 10;
                            }
                        }
                    }
                    if (rivalCar.nodes.Count == 0)
                    {
                        field.RivalCars.Remove(rivalCar);
                    }
                }
            } while (!field.IsMainCarOnRivalCar());
            this.drawer.DrawGameOver(field);
            Console.ReadLine();
            this.mainMenu.ShowMenu();
        }