Exemple #1
0
        protected void GuessingPlayerActions()
        {
            Console.Clear();
            Console.WriteLine("Guessing player, press any key to start...");
            Console.ReadKey();
            Console.WriteLine("Try guess a number!");

            MaxAttempt = GetMaxAttempt(Min, Max);
            do
            {
                validator = new MinMaxValidator(Min, Max);
                Console.WriteLine($"Min value is {Min} and max is {Max}");
                GuessingPlayerNumber = NumberValidator.ConvertStringToNumber(validator);

                if (GuessingPlayerNumber > GuessingNumber)
                {
                    validator.maxValue = validator.IsValid(GuessingPlayerNumber) ? GuessingPlayerNumber : validator.maxValue;
                    Max = (int)validator.maxValue;
                }

                if (GuessingPlayerNumber < GuessingNumber)
                {
                    validator.minValue = validator.IsValid(GuessingPlayerNumber) ? GuessingPlayerNumber : validator.minValue;
                    Min = (int)validator.minValue;
                }

                if (GuessingPlayerNumber == GuessingNumber)
                {
                    IsWin = true;
                }

                Console.WriteLine($"It was your {++Attempt}/{MaxAttempt} attempt");
            } while (!IsWin && Attempt != MaxAttempt);
        }
Exemple #2
0
        public static void StartMainMenu(ref Game game, ref bool exit)
        {
            Console.Clear();
            Console.WriteLine("Menu:");
            Console.WriteLine($"{(int)UserGameTypeChoice.PlayWithAnotherPlayer} - Play with another player");
            Console.WriteLine($"{(int)UserGameTypeChoice.PlayWithComputer} - Play with computer");
            Console.WriteLine($"{(int)UserGameTypeChoice.Exit} - Exit");

            UserGameTypeChoice choice = (UserGameTypeChoice)NumberValidator.ConvertStringToNumber();

            switch (choice)
            {
            case UserGameTypeChoice.PlayWithAnotherPlayer:
            {
                Console.Clear();
                game = new GameVersusPlayer();
                break;
            }

            case UserGameTypeChoice.PlayWithComputer:
            {
                StartLevelMenu(ref game);
                break;
            }

            case UserGameTypeChoice.Exit:
            {
                exit = true;
                break;
            }

            default: break;
            }
        }
Exemple #3
0
        public static void StartLevelMenu(ref Game game)
        {
            Console.Clear();
            Console.WriteLine($"{(int)UserLevelChoice.Easy} - Easy level");
            Console.WriteLine($"{(int)UserLevelChoice.Medium} - Medium level");
            Console.WriteLine($"{(int)UserLevelChoice.Hard} - Hard level");
            UserLevelChoice choiceLevel = (UserLevelChoice)NumberValidator.ConvertStringToNumber();

            switch (choiceLevel)
            {
            case UserLevelChoice.Easy:
            {
                game = new EasyLevelGame();
                break;
            }

            case UserLevelChoice.Medium:
            {
                game = new MediumLevelGame();
                break;
            }

            case UserLevelChoice.Hard:
            {
                game = new HardLevelGame();
                break;
            }

            default: break;
            }
        }
Exemple #4
0
        private void FirstPlayerActions()
        {
            validator = new MinMaxValidator();

            Console.WriteLine("First player, Enter min value");
            validator.minValue = NumberValidator.ConvertStringToNumber(validator);
            Min = (int)validator.minValue;

            Console.WriteLine("Enter max value");
            validator.maxValue = NumberValidator.ConvertStringToNumber(validator);
            Max = (int)validator.maxValue;

            Console.WriteLine("Enter the guessing number");
            GuessingNumber = NumberValidator.ConvertStringToNumber(validator);

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }