Archive

Posts Tagged ‘Random’

Tutorial #2 – Basic Guess Game in C#

November 10th, 2008 No comments

Here is my new tutorial for you about C#. In this tutorial i am going to make a little game about guessing result of some number summation, multiplation, division and addition. And i am going to focus on handling the enter keypress event for textfield.

Here as you see from the screenshot of the main window a user should guess the result of this operation. Textbox1 equals the random number “96″, textbox2 equals the random number “73″ and there is an randomly operator which is “-” . User should guess this result and should write down the guess into the textbox3 field. When user press enter button textbox3 handles this event.

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13) //Char 13 handles the enter key
{
Console.WriteLine(total);  //Here i can check the result from console for testing purposes
if (total.ToString() == textBox3.Text)
{
StringBuilder dogru_str = new StringBuilder();
dogru_str.Append(textBox1.Text);
dogru_str.Append(" " + label1.Text + " ");
dogru_str.Append(textBox2.Text + " = ");
dogru_str.Append(total + "\n");
dogru_str.Append("Your answer was correct...");
MessageBox.Show(dogru_str.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

Read more…

VN:F [1.9.11_1134]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.11_1134]
Rating: 0 (from 0 votes)