aboutsummaryrefslogtreecommitdiff
path: root/Histacom2/OS/Win95/Win95Apps/GuessTheNumber.cs
blob: 4766c8d8f16166964c0399d1e76a4f1a05010a21 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Histacom2.OS.Win95.Win95Apps
{
    public partial class GuessTheNumber : UserControl
    {
        private Random rnd;
        private int num;

        public GuessTheNumber()
        {
            InitializeComponent();

            rnd = new Random();
            num = rnd.Next(0, 101);
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            pictureBox2.BackgroundImage = null;
            textBox1.Enabled = true;
            num = rnd.Next(0, 101);
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try {
                int guess = int.Parse(textBox1.Text);

                if (guess < num) pictureBox2.BackgroundImage = Properties.Resources.GTN95_Higher;
                else if (guess > num) pictureBox2.BackgroundImage = Properties.Resources.GTN95_Lower;
                else if (guess == num)
                {
                    pictureBox2.BackgroundImage = Properties.Resources.GTN95_Correct;
                    textBox1.Enabled = false;
                }
            } catch
            {
                pictureBox2.BackgroundImage = Properties.Resources.GTN95_Error;
            }
        }
    }
}