コード例 #1
0
        private void ReadCommand(int gameMode, ILevel currentLevel)
        {
            ConsoleSetup.CleaningTheConsoleBuffer();

            string direction            = "right";
            string lastCorrectDirection = direction;

            while (currentLevel.CurrentlyEatenApples != currentLevel.ApplesTarget)
            {
                IsGameOver(currentLevel);
                Borders.PrintBorders();
                currentLevel.CheckForAppleTimeElapsed(currentLevel.Obstacles);
                if (Console.KeyAvailable)
                {
                    var currentCommand = Console.ReadKey(true);
                    if (gameMode == 1)
                    {
                        direction = GameModeOneKeyParser(currentCommand);
                    }
                    else
                    {
                        direction = GameModeTwoKeyParser(currentCommand);
                    }
                    //Checking and ignoring direction if incorrect key is pressed +
                    //Checking and ingnoring direction if opposite direction is chosen
                    CheckingCurrentDirection(ref direction, ref lastCorrectDirection);
                }
                ConsoleSetup.SlowAction(currentLevel.SlowActionGame);
                this.ProcessCommand(direction, currentLevel, currentLevel.Obstacles);
            }
            gamePoints.PositivePoints += currentLevel.AllLevelPoints;
        }
コード例 #2
0
        private void GameStartPreparation(int level)
        {
            Console.Clear();
            string stringOfNewLines            = new string('\n', 18);
            string stringOfTabulationsForLevel = new string('\t', 9);
            string stringOfTabulationsForTime  = new string('\t', 7);

            Console.ForegroundColor = ConsoleColor.White;
            for (int i = initialSecond; i >= finalSecond; i--)
            {
                Console.Write($"{stringOfNewLines}{stringOfTabulationsForLevel}");
                Console.WriteLine($"{Constants.GameLevel} {level}");
                Console.Write($"\n{stringOfTabulationsForTime}");
                Console.Write($"{Constants.GameStartPreparation} {i} sec.");
                ConsoleSetup.SlowAction(1000);
                Console.Clear();
            }
        }