-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
205 lines (186 loc) · 7.14 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace n1
{
public partial class Form1 : Form
{
Random tangoRand = new Random();
//int wa,wa2;
//string va,va2;
string fav;
string temp;
//allTango为每行组成的字符串数组
string[] allTango, favSet, tempTango;
//tango为单行拆开后的字符串数组,重复使用
string[] tango = new string[6];
int tangoAmount, testAmount, right, track;
int i, answer;
Color dftCol = Color.FromName("control");
Color ansCol = Color.FromName("LightGreen");
RadioButton[] options = new RadioButton[4];
//tangoIndex是所有元素(全部或fav)的索引
//index是单次循环中随机提取的4个元素的索引
int[] tangoIndex, index;
//int[] optIndex = { 1, 2, 3, 4 };
char[] delimLine = { '\n' };
char[] delimField = { ',' };
public Form1()
{
InitializeComponent();
options[0] = ckA;
options[1] = ckB;
options[2] = ckC;
options[3] = ckD;
}
private void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
boxAmount.Enabled = false;
ckLog.Enabled = false;
ckFav.Enabled = false;
ckA.Visible = true;
ckB.Visible = true;
ckC.Visible = true;
ckD.Visible = true;
btnNext.Visible = true;
System.IO.StreamReader fileTango = new System.IO.StreamReader(@"D:\N1.txt");
temp = fileTango.ReadToEnd();
fileTango.Close();
allTango = temp.Split(delimLine);
tangoAmount = allTango.Length;
track = 1;
right = 0;
stsScore.Text = "Right: " + right.ToString();
//勾选fav,则读取fav.txt的内容(单行数字组成的逗号分隔符文件)
//同时tangoIndex的元素就是fav的单个数字
//默认fav中的数字总数不小于4
if (ckFav.Checked)
{
System.IO.StreamReader fileFav = new System.IO.StreamReader(@"D:\fav.txt");
fav = fileFav.ReadLine();
favSet = fav.Split(delimField);
fileFav.Close();
tangoIndex = new int[favSet.Length];
for (i = 0; i < favSet.Length; i++)
tangoIndex[i] = Convert.ToInt16(favSet[i]);
}
//不勾选fav,tangoIndex的元素就是0到allTango.Length-1的序数
else
{
tangoIndex = new int[allTango.Length];
for (i = 0; i < allTango.Length; i++)
tangoIndex[i] = i;
}
tangoAmount = tangoIndex.Length;
testAmount = Convert.ToInt16(boxAmount.Text);
txtAll.Text = testAmount.ToString();
txtCurrent.Text = "1";
//每次循环,从tangoIndex里面随机提取4个元素,作为索引
//单次提取的4个元素不重复,多次循环中提取的元素允许重复
//用tempTango代替allTango进行操作,避免allTango元素被修改
tempTango = new string[allTango.Length];
allTango.CopyTo(tempTango, 0);
//tempTango = allTango;
index = new int[4];
for (i = 0; i < 4; i++)
{
index[i] = tangoRand.Next(0, tangoAmount - i);
tango = tempTango[tangoIndex[index[i]]].Split(delimField);
tempTango[tangoIndex[index[i]]] = tempTango[tangoIndex[tangoAmount - 1 - i]];
options[i].Text = tango[3];
}
answer = tangoRand.Next(0, 4);
txtTango.Text = allTango[tangoIndex[index[answer]]].Split(delimField)[0];
}
private void ckA_CheckedChanged(object sender, EventArgs e)
{
options[answer].BackColor = ansCol;
ckA.Enabled = false;
ckB.Enabled = false;
ckC.Enabled = false;
ckD.Enabled = false;
if (answer == 0 && ckA.Checked)
{
right++;
stsScore.Text = "Right: " + right.ToString();
}
}
private void ckB_CheckedChanged(object sender, EventArgs e)
{
options[answer].BackColor = ansCol;
ckA.Enabled = false;
ckB.Enabled = false;
ckC.Enabled = false;
ckD.Enabled = false;
if (answer == 1 && ckB.Checked)
{
right++;
stsScore.Text = "Right: " + right.ToString();
}
}
private void ckC_CheckedChanged(object sender, EventArgs e)
{
options[answer].BackColor = ansCol;
ckA.Enabled = false;
ckB.Enabled = false;
ckC.Enabled = false;
ckD.Enabled = false;
if (answer == 2 && ckC.Checked)
{
right++;
stsScore.Text = "Right: " + right.ToString();
}
}
private void ckD_CheckedChanged(object sender, EventArgs e)
{
options[answer].BackColor = ansCol;
ckA.Enabled = false;
ckB.Enabled = false;
ckC.Enabled = false;
ckD.Enabled = false;
if (answer == 3 && ckD.Checked)
{
right++;
stsScore.Text = "Right: " + right.ToString();
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (track < testAmount)
{
track++;
txtCurrent.Text = track.ToString();
//还原颜色
ckA.Checked = false;
ckB.Checked = false;
ckC.Checked = false;
ckD.Checked = false;
ckA.Enabled = true;
ckB.Enabled = true;
ckC.Enabled = true;
ckD.Enabled = true;
ckA.BackColor = dftCol;
ckB.BackColor = dftCol;
ckC.BackColor = dftCol;
ckD.BackColor = dftCol;
//重置tempTango
allTango.CopyTo(tempTango, 0);
for (i = 0; i < 4; i++)
{
index[i] = tangoRand.Next(0, tangoAmount - i);
tango = tempTango[tangoIndex[index[i]]].Split(delimField);
tempTango[tangoIndex[index[i]]] = tempTango[tangoIndex[tangoAmount - 1 - i]];
options[i].Text = tango[0];
}
answer = tangoRand.Next(0, 4);
txtTango.Text = allTango[tangoIndex[index[answer]]].Split(delimField)[0];
}
}
}
}