Random类,ArrayList实现随机数不重复!在线等答案!

peng2739956 peng2739956 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我做了个英语默写器 实现了一个 随机显示的单词或者解释不重复的功能 但是有问题 大家帮忙看看 哪里需要改。。
在线等答案!!!

namespace 单词背诵
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] words;
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
button1.Enabled = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
words= File.ReadAllLines(openFileDialog1.FileName,Encoding.Default);
}
}
int i=0;
string[] str3;
string str1,str2;
Random rn=new Random();
ArrayList list = new ArrayList();
private void button1_Click(object sender, EventArgs e)
{
try
{
list.Add(s);
Word(s);
}
catch
{
MessageBox.Show("请选择词库");
}
}
private void Word(int str)
{
str3 = words[str].Split('[');
str1 = str3[0].ToString();
str2 = str3[1].ToString();
button1.Enabled = false;
textBox2.Focus();
if (s % 2 == 0)
{
i = 1;
textBox1.Text = str2;
return;
}
if (s % 2 != 0)
{
i = 2;
textBox1.Text = str1;
return;
}
}
int s = 0;
private int List()
{
s = rn.Next(0, words.Length - 1);
return s;
}
int p1, p2;
private void button3_Click(object sender, EventArgs e)
{
switch (i)
{
case 1:
if (str1 == textBox2.Text.Trim())
{
p1 = List();
if (list.Contains(p1))
{
p2 = List();
}
if (list.Contains(p1) == false)
{
list.Add(p1);
textBox1.Clear();
textBox2.Clear();
Word(p1);
}
return;
}
if (str1 != textBox2.Text.Trim())
{
textBox2.Text = "";
MessageBox.Show("回答错误");
return;
}
break;
case 2:
if (str2.Contains(textBox2.Text.Trim()))
{

p1 = List();
if (list.Contains(p1))
{
p2 = List();
}
if (list.Contains(p1) == false)
{
list.Add(p1);
textBox1.Clear();
textBox2.Clear();
Word(p1);
}
return;
}
if (!str2.Contains(textBox2.Text.Trim()))
{
textBox2.Text = "";
MessageBox.Show("回答错误");
return;
}
break;
}
foreach (int[] sr in list)
{
if (sr.Length == words.Length)
{
MessageBox.Show("此单词库的单词全部默写完毕");
}
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
button3_Click(null, null);
}
}
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
peng2739956
C# 111,128 成员 642,536 内容