Пример #1
0
        private static List <int> PromptUntilValidGuess(ConsoleMessageWriter consoleMessageWriter)
        {
            List <int> inputNums       = new List <int>();
            bool       foundValidInput = false;

            while (!foundValidInput)
            {
                inputNums.Clear();
                string userInput = Console.ReadLine();
                foreach (char digit in userInput)
                {
                    if (char.IsDigit(digit))
                    {
                        int theNum = int.Parse(digit.ToString());
                        if (theNum >= START_NUM && theNum <= END_NUM)
                        {
                            inputNums.Add(theNum);
                        }
                    }
                }
                foundValidInput = inputNums.Count == CODE_LENGTH;
                if (!foundValidInput)
                {
                    consoleMessageWriter.WriteNotValidCode();
                }
            }
            return(inputNums);
        }
Пример #2
0
        static void Main(string[] args)
        {
            ConsoleMessageWriter consoleMessageWriter = new ConsoleMessageWriter(CODE_LENGTH, TURNS, START_NUM, END_NUM, RIGHT_CHAR, WRONG_CHAR);
            List <int>           realCode             = MakeStartList();

            consoleMessageWriter.WriteStartMessageToConsole();
            bool hasWon = false;
            int  turn   = 1;

            while (!hasWon && turn <= TURNS)
            {
                hasWon = TakeTurn(consoleMessageWriter, realCode, turn);
                turn++;
            }
            if (hasWon)
            {
                consoleMessageWriter.WriteWinMessageToConsole();
            }
            else
            {
                consoleMessageWriter.WriteLoseMessageToConsole();
            }
            consoleMessageWriter.WriteEndLine();
            Console.ReadLine();
        }
Пример #3
0
        private static bool TakeTurn(ConsoleMessageWriter consoleMessageWriter, List <int> realCode, int turn)
        {
            consoleMessageWriter.WriteTurnStartInstructionsToConsole(turn);
            List <int> guessCode = PromptUntilValidGuess(consoleMessageWriter);

            consoleMessageWriter.WriteResult(GetCompareString(realCode, guessCode));

            return(guessCode.SequenceEqual(realCode));
        }