예제 #1
0
        private void confirmButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int userGuessNumber = int.Parse(numberFromTextBox.Text);

                if (userGuessNumber > generator.maxValue || userGuessNumber < generator.minValue)
                {
                    throw new NumberExeption();
                }
                if (userGuessNumber == generator.number)
                {
                    MessageBox.Show("You guessed. Correct number is " + generator.number, "Guessed", MessageBoxButton.OK);
                    this.Close();
                }
                else
                {
                    if (tryCounter == 1)
                    {
                        tryCounter = 3;
                        generator  = new GenerationModule();
                        MessageBox.Show("New number generated. Try again.\n" + tryCounter + " attempts left  ", "Not guessed", MessageBoxButton.OK);
                    }
                    else
                    {
                        tryCounter--;
                        MessageBox.Show("Try again.   \n" + tryCounter + " attempts left  ", "Not guessed", MessageBoxButton.OK);
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Field must not be empty. Enter integer number.", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (NumberExeption)
            {
                MessageBox.Show("Field must be in a special range(from " + generator.minValue + " to " + generator.maxValue + ")", "Empty field", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
 public MainWindow()
 {
     InitializeComponent();
     generator          = new GenerationModule();
     infoLabel.Content += "from " + generator.minValue + " to " + generator.maxValue;
 }