/// <summary>
        /// This example creates instances for each input value and sets different label colors.
        /// Each instance reads a different type of value (string, int, DateTime, float)
        /// </summary>
        private static void RunExample()
        {
            // Create the input controls
            ValueView <int> ageView = new ValueView <int>("Age:");

            ageView.Label.ForegroundColor = ConsoleColor.DarkGreen;

            // Read values using the input controls
            int age = ageView.Read();

            // Display th read values.
            CustomConsole.WriteLine();
            CustomConsole.WriteLine("You are {0} years old.", age);
        }
        private static void RunExample()
        {
            ValueView <int> numberView = new ValueView <int>("Number ({0}):");

            numberView.AcceptDefaultValue = true;
            numberView.DefaultValue       = 42;

            CustomConsole.WriteLine("Just hit enter. The default value, 42, is returned by the ValueView control.");
            CustomConsole.WriteLine();

            int number = numberView.Read();

            CustomConsole.WriteLine();
            CustomConsole.WriteLine("You selected {0}.", number);
        }
예제 #3
0
        /// <summary>
        /// This example creates instances for each input value and sets different label colors.
        /// Each instance reads a different type of value (string, int, DateTime, float)
        /// </summary>
        private static void RunExample()
        {
            // Create the input controls

            ValueView <string> firstNameView = new ValueView <string>("First Name:");

            firstNameView.Label.ForegroundColor = ConsoleColor.Cyan;

            ValueView <string> lastNameView = new ValueView <string>("Last Name:");

            lastNameView.Label.ForegroundColor = ConsoleColor.Cyan;

            // Read values using the input controls
            string firstName = firstNameView.Read();
            string lastName  = lastNameView.Read();

            // Display the read values.
            CustomConsole.WriteLine();
            CustomConsole.WriteLine("Hi, {0} {1}!", firstName, lastName);
        }
예제 #4
0
        public void Run()
        {
            while (currentWord.GetLettersRemaining() > 0 && hangingMan.IsDead() == false)
            {
                Console.Clear();
                if (incorrectGuesses.Count > 0)
                {
                    incorrectGuessesControl.UpdateIncorrectGuesses(incorrectGuesses);
                    incorrectGuessesControl.Display();
                }
                hangManControl.Display();
                currentWordControl.ChangeDisplayedWord(currentWord.GetWord());
                currentWordControl.Display();

                // Block awaiting input
                char letter = nextGuessControl.Read();

                // Update the hanging man if answer incorrect
                if (!currentWord.UnmaskLetter(letter))
                {
                    hangingMan.SubtractLife();
                    incorrectGuesses.Add($"{letter}");
                }
            }

            // The game is now over!
            Console.Clear();
            gameOverScreen.Won = !hangingMan.IsDead();
            gameOverScreen.Display();

            if (YesNoQuestion.QuickRead("Play again?", YesNoAnswer.No).HasFlag(YesNoAnswer.Yes))
            {
                incorrectGuesses.Clear();
                incorrectGuessesControl.ResetIncorrectGuesses();
                hangingMan.ResetStickFigure();
                currentWord = new Word(allTheWords.PickRandomWord());
                currentWordControl.ChangeDisplayedWord(currentWord.GetWord());
                Run();
            }
        }
예제 #5
0
 public object Display()
 {
     return(input.Read());
 }
        private void ChangePrompter()
        {
            ValueView <string> valueView = new ValueView <string>("New Prompter Text:");

            prompter.Text = valueView.Read();
        }
예제 #7
0
        public object Display()
        {
            List <string> values = new List <string>();

            questions.ForEach(input =>
            {
                Type type = input.ItemType;

                if (string.IsNullOrEmpty(input.ValidationErrorMessage))
                {
                    input.ValidationErrorMessage = "Input is not in correct format";
                }

                switch (type.Name)
                {
                case "Int32":
                    var valueViewInt = new ValueView <int>(input.Question);
                    valueViewInt.CursorPositionChanged = OnCursorPositionChanged;

                    valueViewInt.Label.ForegroundColor = captionColor;

                    valueViewInt.TypeConversionErrorMessage = input.ValidationErrorMessage;

                    valueViewInt.CustomParser = delegate(string inputValue)
                    {
                        if (int.TryParse(inputValue, out int result))
                        {
                            if (input.Validator != null)
                            {
                                if (!input.Validator(inputValue))
                                {
                                    if (!string.IsNullOrEmpty(input.ValidationErrorMessage))
                                    {
                                        throw new Exception(input.ValidationErrorMessage);
                                    }
                                }
                            }
                        }
                        else
                        {
                            throw new Exception(input.ValidationErrorMessage);
                        }

                        return(result);
                    };

                    values.Add(valueViewInt.Read().ToString()); break;

                case "String":
                    var valueViewString = new ValueView <string>(input.Question);
                    valueViewString.CursorPositionChanged = OnCursorPositionChanged;

                    valueViewString.Label.ForegroundColor = captionColor;

                    valueViewString.TypeConversionErrorMessage = input.ValidationErrorMessage;

                    valueViewString.CustomParser = delegate(string inputValue)
                    {
                        if (!string.IsNullOrEmpty(inputValue))
                        {
                            if (input.Validator != null)
                            {
                                if (!input.Validator(inputValue))
                                {
                                    if (!string.IsNullOrEmpty(input.ValidationErrorMessage))
                                    {
                                        throw new Exception(input.ValidationErrorMessage);
                                    }
                                }
                            }
                        }
                        else
                        {
                            throw new Exception(input.ValidationErrorMessage);
                        }

                        return(inputValue);
                    };

                    values.Add(valueViewString.Read().ToString()); break;
                }
            });

            return(values);
        }