Exemplo n.º 1
0
        private void ButtonGuess_Click(object sender, EventArgs e)
        {
            int userGuess;

            if (int.TryParse(TextBoxGuess.Text, out userGuess))
            {
                /* Check can 0: num is lower, 1: num is higher,
                 * 2: guess is correct! */
                int guessCheck = Game.CheckGuess(userGuess);
                if (guessCheck == 2)
                {
                    /* Pop a message box and reset game */
                    MessageBox.Show("Correct! " +
                                    "New random number generated");
                    Game.GenerateNewNumber();
                    TextBoxGuess.Clear(); // Clear guess textbox
                }

                else
                {
                    string text = (guessCheck == 0) ?
                                  "lower!" : "higher";

                    textBox1.Text = string.Format(
                        "You guessed {0}\r\nThe number is {1}",
                        userGuess,
                        text);
                }

                /* Select guess textbox and
                 * focus text cursor */
                TextBoxGuess.Focus();
                TextBoxGuess.SelectAll();
            }
        }
Exemplo n.º 2
0
 private void ClearGuessList()
 {
     InvokeGui(() =>
     {
         _viewModel.Guesses.Clear();
         TextBoxGuess.Clear();
     });
 }
Exemplo n.º 3
0
        private void TextBoxGuess_OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && !String.IsNullOrWhiteSpace(TextBoxGuess.Text))
            {
                var guessedWord = TextBoxGuess.Text;

                _client.EnqueueDataForWrite(new WordGuessPackage(guessedWord, _viewModel.MatchUid, App.Uid, App.Uid, Router.ServerWildcard));
                TextBoxGuess.Clear();
            }
        }
Exemplo n.º 4
0
        public GuessNumber()
        {
            InitializeComponent();

            Game.GenerateNewNumber();
            TextBoxGuess.Text = "0";
            TextBoxGuess.Focus();
            TextBoxGuess.SelectAll();
            textBox1.Select(0, 0);
        }