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

peng2739956 2010-11-25 04:54:26
我做了个英语默写器 实现了一个 随机显示的单词或者解释不重复的功能 但是有问题 大家帮忙看看 哪里需要改。。
在线等答案!!!

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);
}
}
...全文
187 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧