ztlhd
public partial class Form1 : Form
    {
        string[] chengfa = null;
        string[] Games = null;
        string[] names = null;
        int i = 0;
        int a = 0;
        int b = 0;
        string name = "";
        string name1 = "";
        public Form1()
        {
            InitializeComponent();
            Games = File.ReadAllLines(Application.StartupPath + "/游戏.txt", Encoding.Default);
            chengfa = File.ReadAllLines(Application.StartupPath + "/惩罚.txt", Encoding.Default);
            names = File.ReadAllLines(Application.StartupPath + "/人员名单.txt", Encoding.Default);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.timer2.Stop();
            this.timer3.Stop();
            this.timer1.Start();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
            this.timer3.Stop();
            this.timer2.Start();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            this.timer2.Stop();
            ArrayList ii = new ArrayList(chengfa);//把chengfa数组复制到ArrayLise中,便于删除
            if (i == 15)
            {
                ii.Remove(chengfa[15]);//删除随机位置8的那个元素
                chengfa = new string[ii.Count];//重新定义chengfa数组的个数
                ii.CopyTo(chengfa);// 把ii复制到chengfa中,从而生成一个名字还是惩罚的数组,但是元素8被删除了
            }
            if (i == 14)
            {
                ii.Remove(chengfa[14]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 13)
            {
                ii.Remove(chengfa[13]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 12)
            {
                ii.Remove(chengfa[12]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 11)
            {
                ii.Remove(chengfa[11]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 10)
            {
                ii.Remove(chengfa[10]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 9)
            {
                ii.Remove(chengfa[9]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 8)
            {
                ii.Remove(chengfa[8]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 7)
            {
                ii.Remove(chengfa[7]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 6)
            {
                ii.Remove(chengfa[6]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 5)
            {
                ii.Remove(chengfa[5]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 4)
            {
                ii.Remove(chengfa[4]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 3)
            {
                ii.Remove(chengfa[3]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 2)
            {
                ii.Remove(chengfa[2]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
            if (i == 1)
            {
                ii.Remove(chengfa[1]);
                chengfa = new string[ii.Count];
                ii.CopyTo(chengfa);
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            Random ran = new Random();
            i = ran.Next(Games.Length);
            string name = Games[i];
            this.label3.Text = name;
          
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            Random dada = new Random();
            i = dada.Next(chengfa.Length);//返回一个随机数,数字大小不超过chengfa数组的长度
            string name = chengfa[i];
            this.label3.Text = name;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
            this.timer2.Stop();
            if (names.Length != 0)
            {
                this.timer3.Start();
            }
            else
            {
                this.timer3.Stop();
                MessageBox.Show("没有人啦");
            }
        }
        int da = 1;
        int c = 0;
        private void button5_Click(object sender, EventArgs e)
        {
            if (timer3.Enabled == true)
            {
                c++;
                if (c % 3 == 1)
                {
                    this.label1.Text = label1.Text + "----------------------------------\n";
                }
                this.timer3.Stop();
                this.label1.Text = label1.Text + "第" + da.ToString() + "组:" + name + name1 + "\n";//name , name1抽出的人员名字
                ArrayList ii = new ArrayList(names);
                ii.Remove(names[a]);
                ii.Remove(names[b]);
                names = new string[ii.Count];
                ii.CopyTo(names);
                da++;
            }
            else
            {
                MessageBox.Show("已经关闭啦");
            }
        }
        private void timer3_Tick(object sender, EventArgs e)
        {
                Random random = new Random();
                a = random.Next(names.Length);
                name = names[a];
                b = random.Next(names.Length);
                name1 = names[b];
            if (a !=b)
            {
               this.label3.Text = name + name1;
            }
            else
            {
                a = random.Next(names.Length);
                name = names[a];
                b = random.Next(names.Length);
                name1 = names[b];
                this.label3.Text = name + name1;
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            names = File.ReadAllLines(Application.StartupPath + "/人员名单.txt", Encoding.Default);
            this.label1.Text = null;
            da = 1;
        }
---------------------

 

分类:

技术点:

相关文章: