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(); } }
private void ClearGuessList() { InvokeGui(() => { _viewModel.Guesses.Clear(); TextBoxGuess.Clear(); }); }
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(); } }