Пример #1
0
        private void generateAnswerDigits()
        {
            // generate a specific number of random digits, each with a value between the min and max
            Random random = new Random();

            for (int i = 0; i < answerDigits.Length; i++)
            {
                answerDigits[i] = new DigitCounter(random.Next(MIN_DIGIT, MAX_DIGIT + 1));
            }
        }
Пример #2
0
        private void getNextGuess()
        {
            int numChars = 0;

            while (numChars < NUM_DIGITS)
            {
                // get the next character, but only accept certain values
                ConsoleKeyInfo inputChar = Console.ReadKey(true);
                if (inputChar.KeyChar >= '1' && inputChar.KeyChar <= '6')
                {
                    guessDigits[numChars] = new DigitCounter(int.Parse(inputChar.KeyChar.ToString()));
                    Console.Write(inputChar.KeyChar);
                    numChars++;
                }
                // also allow Backspace to delete the last character
                else if (inputChar.Key == ConsoleKey.Backspace && numChars > 0)
                {
                    Console.Write("\b \b");
                    numChars--;
                }
            }
        }