c#之双色球

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;
using System.Threading;

namespace 摇奖机程序
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        bool b = false;
        private void button1_Click(object sender, EventArgs e)
        {
            if (b == false)
            {
               
                b = true;
                int num = int.Parse(this.textBox1.Text);
                button1.Text = "停止";
                Thread th = new Thread(PlayGame);
                th.IsBackground = true;
                th.Name = "新线程";
                // th.
                th.Start(num);
            }
            else//b==true
            {
                b = false;
                button1.Text = "开始";
            }
            //PlayGame();
        }
        private void PlayGame(object ss)
        {
            Random r = new Random();
            while (b)
            {
                listBox1.Items.Clear();
                int num = (int)ss;
                for (int i = 0; i < num; i++) 
                {
                    //int[] nums = new int[6];
                    List<int> nums = new List<int>();
                    for (int j = 0; j < 6; j++) 
                    {
                        int cu = r.Next(1, 34);
                        if (nums.Contains(cu))
                        {
                            j--;
                        }
                        else 
                        {
                            nums.Add(cu);
                        }
                    }

                    nums.Sort();
                    int lan=r.Next(1,17);
                    string zu = nums[0].ToString() + " " + nums[1].ToString() + " " + nums[2].ToString() + " " + nums[3].ToString() + " " + nums[4].ToString() + " " + nums[5].ToString() + "-" + lan;
                    listBox1.Items.Add(zu);

                    
                  
                }


            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false;
        }

    }
}

  

转载于:https://www.cnblogs.com/mengluo/p/5582801.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值