-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
90 lines (81 loc) · 2.76 KB
/
Form1.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
numberOfTries = 0;
number = random.Next(1, 2001);
}
Random random = new Random();
int numberOfTries;
int number;
private void ResumeButton_Click(object sender, EventArgs e)
{
string message = "My Name is Gurbanov Kanan";
string allchars = message;
DialogResult result = MessageBox.Show(message,"Resume",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
if (result==DialogResult.Cancel)
{
Close();
}
else
{
message = "I am STEP and UFAZ Student";
allchars += message;
result = MessageBox.Show(message, "Resume", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.Cancel)
{
Close();
}
else
{
message = "And I love pizza.\n";
allchars += message;
result = MessageBox.Show($"{message}Average Number of chars:{allchars.Length/3}", "Resume", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
Close();
}
}
}
}
private void TryButton_Click(object sender, EventArgs e)
{
numberOfTries++;
int userNum = int.Parse(textBox1.Text);
if (number==userNum)
{
DialogResult result= MessageBox.Show($"You won!\nNumber of tries:{numberOfTries}","Guess the Number",MessageBoxButtons.RetryCancel,MessageBoxIcon.Information);
if (result==DialogResult.Retry)
{
numberOfTries = 0;
number = random.Next(1, 2001);
}
}
else
{
string mes = String.Empty;
if (number>userNum)
{
mes = "higher";
}
else
{
mes = "lower";
}
MessageBox.Show($"Wrong!\nMy number is {mes}.", "Guess the Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}