-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
249 lines (234 loc) · 8.32 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// Decompiled with JetBrains decompiler
// Type: WindowsFormsApp2.Form1
// Assembly: WindowsFormsApp2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6D991277-C4E9-46C5-9894-13C427645C33
// Assembly location: C:\Users\huso\source\repos\WindowsFormsApp2\WindowsFormsApp2\obj\Debug\WindowsFormsApp2.exe
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public class Form1 : Form
{
private IContainer components = (IContainer) null;
private Label label1;
private Label label2;
private Button btnStart;
private Label labelQue;
private TextBox txtAnswer;
private Button btnChk;
private Label labelTrue;
private Label labelFalse;
private GroupBox groupBox1;
private Label wrongCount;
private Label correctCount;
private Label gameCount;
public int number1 { get; set; }
public int number2 { get; set; }
public char op { get; set; }
public int Game { get; set; }
public int Correct { get; set; }
public int Wrong { get; set; }
public Form1() => this.InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
{
this.Game = this.Correct = this.Wrong = 0;
this.updateScore();
}
private void updateScore()
{
this.gameCount.Text = "Game" + this.Game.ToString();
this.correctCount.Text = "Correct" + this.Correct.ToString();
this.wrongCount.Text = "Wrong" + this.Wrong.ToString();
}
private void btnStart_Click(object sender, EventArgs e)
{
Random random = new Random();
this.number1 = random.Next(0, 101);
this.number2 = random.Next(0, 101);
switch (random.Next(4))
{
case 0:
this.op = '+';
break;
case 1:
this.op = '-';
break;
case 2:
this.op = '*';
break;
case 3:
this.op = '/';
break;
}
this.labelQue.Text = string.Format("{0} {1} {2} = ", (object) this.number1, (object) this.op, (object) this.number2);
this.labelQue.Visible = true;
this.txtAnswer.Visible = true;
this.btnChk.Visible = true;
this.labelTrue.Visible = false;
this.labelFalse.Visible = false;
this.updateScore();
}
private void btnChk_Click(object sender, EventArgs e)
{
int num1 = 0;
int result = 0;
switch (this.op)
{
case '*':
num1 = this.number1 * this.number2;
break;
case '+':
num1 = this.number1 + this.number2;
break;
case '-':
num1 = this.number1 - this.number2;
break;
case '/':
num1 = this.number1 / this.number2;
break;
}
if (!int.TryParse(this.txtAnswer.Text, out result))
{
int num2 = (int) MessageBox.Show("INVALID NUMBER");
this.txtAnswer.Focus();
this.txtAnswer.SelectAll();
}
else
{
if (num1 == result)
{
this.labelTrue.Visible = true;
++this.Correct;
}
else
{
this.labelFalse.Visible = true;
++this.Wrong;
}
++this.Game;
this.updateScore();
}
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.label1 = new Label();
this.label2 = new Label();
this.btnStart = new Button();
this.labelQue = new Label();
this.txtAnswer = new TextBox();
this.btnChk = new Button();
this.labelTrue = new Label();
this.labelFalse = new Label();
this.groupBox1 = new GroupBox();
this.wrongCount = new Label();
this.correctCount = new Label();
this.gameCount = new Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
this.label1.AutoSize = true;
this.label1.Location = new Point(12, 33);
this.label1.Name = "label1";
this.label1.Size = new Size(49, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Describe";
this.label2.Location = new Point(26, 59);
this.label2.Name = "label2";
this.label2.Size = new Size(243, 77);
this.label2.TabIndex = 1;
this.label2.Text = "1-asdasdasdasd\r\n2-asdasdsad";
this.btnStart.Location = new Point(29, 112);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new Size(75, 23);
this.btnStart.TabIndex = 2;
this.btnStart.Text = "StartGame";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new EventHandler(this.btnStart_Click);
this.labelQue.Font = new Font("Microsoft Sans Serif", 14.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 162);
this.labelQue.Location = new Point(29, 152);
this.labelQue.Name = "labelQue";
this.labelQue.Size = new Size(100, 23);
this.labelQue.TabIndex = 3;
this.labelQue.Text = "15 + 25 =";
this.labelQue.Visible = false;
this.txtAnswer.Location = new Point(135, 154);
this.txtAnswer.Name = "txtAnswer";
this.txtAnswer.Size = new Size(100, 20);
this.txtAnswer.TabIndex = 4;
this.txtAnswer.Visible = false;
this.btnChk.Location = new Point(247, 152);
this.btnChk.Name = "btnChk";
this.btnChk.Size = new Size(75, 23);
this.btnChk.TabIndex = 5;
this.btnChk.Text = "Check";
this.btnChk.UseVisualStyleBackColor = true;
this.btnChk.Visible = false;
this.btnChk.Click += new EventHandler(this.btnChk_Click);
this.labelTrue.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 162);
this.labelTrue.ForeColor = Color.Green;
this.labelTrue.Location = new Point(26, 192);
this.labelTrue.Name = "labelTrue";
this.labelTrue.Size = new Size(109, 23);
this.labelTrue.TabIndex = 6;
this.labelTrue.Text = "Congratulations";
this.labelTrue.Visible = false;
this.labelFalse.Font = new Font("Microsoft Sans Serif", 9.75f, FontStyle.Regular, GraphicsUnit.Point, (byte) 162);
this.labelFalse.ForeColor = Color.Red;
this.labelFalse.Location = new Point(26, 226);
this.labelFalse.Name = "labelFalse";
this.labelFalse.Size = new Size(100, 23);
this.labelFalse.TabIndex = 7;
this.labelFalse.Text = "Wrong Answer";
this.labelFalse.Visible = false;
this.groupBox1.Controls.Add((Control) this.wrongCount);
this.groupBox1.Controls.Add((Control) this.correctCount);
this.groupBox1.Controls.Add((Control) this.gameCount);
this.groupBox1.Location = new Point(222, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new Size(136, 100);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Score";
this.wrongCount.Location = new Point(12, 70);
this.wrongCount.Name = "wrongCount";
this.wrongCount.Size = new Size(100, 23);
this.wrongCount.TabIndex = 2;
this.wrongCount.Text = "Wrong : 3";
this.correctCount.Location = new Point(12, 47);
this.correctCount.Name = "correctCount";
this.correctCount.Size = new Size(100, 23);
this.correctCount.TabIndex = 1;
this.correctCount.Text = "Correct : 2";
this.gameCount.Location = new Point(12, 21);
this.gameCount.Name = "gameCount";
this.gameCount.Size = new Size(100, 23);
this.gameCount.TabIndex = 0;
this.gameCount.Text = "Game : 5";
this.AutoScaleDimensions = new SizeF(6f, 13f);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new Size(371, 258);
this.Controls.Add((Control) this.groupBox1);
this.Controls.Add((Control) this.labelFalse);
this.Controls.Add((Control) this.labelTrue);
this.Controls.Add((Control) this.btnChk);
this.Controls.Add((Control) this.txtAnswer);
this.Controls.Add((Control) this.labelQue);
this.Controls.Add((Control) this.btnStart);
this.Controls.Add((Control) this.label2);
this.Controls.Add((Control) this.label1);
this.Name = nameof (Form1);
this.Text = nameof (Form1);
this.Load += new EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
}
}