Advertisement
aslen

Untitled

May 19th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace GameRandomNubmer
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         private Random random;
  16.         private int numbRandom;
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         protected override void OnLoad(EventArgs e)
  23.         {
  24.             CalculateRandomNumber();
  25.         }
  26.         private void EnterButtonClick(object sender, EventArgs e)
  27.         {
  28.             int textBoxNumber = int.Parse(textBox1.Text);
  29.             if (textBoxNumber == numbRandom)
  30.                 textBox2.Text = "You win!!!";
  31.             else
  32.             {
  33.                 textBox2.Text = "Try again";
  34.                 textBox1.Text = string.Empty;
  35.             }
  36.         }
  37.         private void NewButtonClick(object sender, EventArgs e)
  38.         {
  39.             CalculateRandomNumber();
  40.         }
  41.  
  42.         private void textBox1_MouseClick(object sender, MouseEventArgs e)
  43.         {
  44.             ClearTextBoxs();
  45.         }
  46.         private void CalculateRandomNumber()
  47.         {
  48.             random = new Random();
  49.             numbRandom = random.Next(1, 10);
  50.             if ((textBox1.Text != string.Empty) && (textBox2.Text != string.Empty))
  51.                 ClearTextBoxs();
  52.         }
  53.         private void ClearTextBoxs()
  54.         {
  55.             textBox1.Text = textBox2.Text = string.Empty;
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement