本人新手一枚,想用C#窗体写一个双色球的游戏,请高手们指点指点~~
//用于存放1到33这33个
List<int> container = new List<int>(33);
List<int> result = new List<int>(6);
//定义抽奖次数,双色球6+1
int j = 1;
int count = 0;
public void Award()
{
count++;
if (count == 7)
{
sorkAward();
MessageBox.Show("本期开奖结束!");
this.btnAward.Enabled = false;
}
}
//初始化数组
public void InitArray()
{
for (int i = 1; i < 33; i++)
{
container.Add(i);
}
}
public void RedRandom()
{
Random rd = new Random();
//随机生成蓝球
Random rdblue = new Random();
int mathblue = rdblue.Next(1, 12);
int index = 0;
int value = 0;
//从[0,container.Count]中取一个随机值,保证这个值不会超过container的元素个数
index = rd.Next(0, container.Count);
value = container[index];
container.RemoveAt(index);
//遍历所有文本框
foreach (Control c in Controls)
{
//判断类型为TextBox
if (c is TextBox)
{
if (c.Name == "txt1" && txt1.Text == "")
{
this.txt1.Text = value.ToString();
this.txt2.Text = "";
this.txt3.Text = "";
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt2" && txt2.Text == "")
{
this.txt2.Text = value.ToString();
this.txt3.Text = "";
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt3" && txt3.Text == "")
{
this.txt3.Text = value.ToString();
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt4" && txt4.Text == "")
{
this.txt4.Text = value.ToString();
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt5" && txt5.Text == "")
{
this.txt5.Text = value.ToString();
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt6" && txt6.Text == "")
{
this.txt6.Text = value.ToString();
this.txtBlue.Text = "";
}
else if (c.Name == "txtBlue" && txtBlue.Text == "")
{
this.txtBlue.Text = mathblue.ToString();
}
}
}
result.Add(value);
container.RemoveAt(index);
}
//点击出奖
private void button1_Click(object sender, EventArgs e)
{
j++;
RedRandom();
Award();
}
//下期开奖
private void button2_Click(object sender, EventArgs e)
{
//初始化数组
InitArray();
count = 0;
foreach (Control c in Controls)
{
if (c is TextBox)
{
c.Text = "";
}
}
this.btnAward.Enabled = true;
}
//开奖后排序,如何依次对文本框赋值?
public void sorkAward() {
result.Sort();
}
}
---------------------------------------------------------
问题一:如何排序生成的中奖号码并显示在文本框内
问题二:如何生成不重复的随机数
List<int> container = new List<int>(33);
List<int> result = new List<int>(6);
//定义抽奖次数,双色球6+1
int j = 1;
int count = 0;
public void Award()
{
count++;
if (count == 7)
{
sorkAward();
MessageBox.Show("本期开奖结束!");
this.btnAward.Enabled = false;
}
}
//初始化数组
public void InitArray()
{
for (int i = 1; i < 33; i++)
{
container.Add(i);
}
}
public void RedRandom()
{
Random rd = new Random();
//随机生成蓝球
Random rdblue = new Random();
int mathblue = rdblue.Next(1, 12);
int index = 0;
int value = 0;
//从[0,container.Count]中取一个随机值,保证这个值不会超过container的元素个数
index = rd.Next(0, container.Count);
value = container[index];
container.RemoveAt(index);
//遍历所有文本框
foreach (Control c in Controls)
{
//判断类型为TextBox
if (c is TextBox)
{
if (c.Name == "txt1" && txt1.Text == "")
{
this.txt1.Text = value.ToString();
this.txt2.Text = "";
this.txt3.Text = "";
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt2" && txt2.Text == "")
{
this.txt2.Text = value.ToString();
this.txt3.Text = "";
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt3" && txt3.Text == "")
{
this.txt3.Text = value.ToString();
this.txt4.Text = "";
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt4" && txt4.Text == "")
{
this.txt4.Text = value.ToString();
this.txt5.Text = "";
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt5" && txt5.Text == "")
{
this.txt5.Text = value.ToString();
this.txt6.Text = "";
this.txtBlue.Text = "";
}
else if (c.Name == "txt6" && txt6.Text == "")
{
this.txt6.Text = value.ToString();
this.txtBlue.Text = "";
}
else if (c.Name == "txtBlue" && txtBlue.Text == "")
{
this.txtBlue.Text = mathblue.ToString();
}
}
}
result.Add(value);
container.RemoveAt(index);
}
//点击出奖
private void button1_Click(object sender, EventArgs e)
{
j++;
RedRandom();
Award();
}
//下期开奖
private void button2_Click(object sender, EventArgs e)
{
//初始化数组
InitArray();
count = 0;
foreach (Control c in Controls)
{
if (c is TextBox)
{
c.Text = "";
}
}
this.btnAward.Enabled = true;
}
//开奖后排序,如何依次对文本框赋值?
public void sorkAward() {
result.Sort();
}
}
---------------------------------------------------------
问题一:如何排序生成的中奖号码并显示在文本框内
问题二:如何生成不重复的随机数
...全文
相关推荐
用C#编写双色球彩票系统
含中奖几率统计。
C#知识|(实例)大乐透双色球随机选号器项目实现(一)
哈喽,你好啊,我是雷工!本节学习练习大乐透双色球随机选号器项目的实现,以下为学习笔记。
c#控制台应用程序双色球游戏
c#控制台应用程序双色球游戏,猜双色球号码,系统产生出随机号码,系统进行对比,最后公布获得的奖金数并询问是否继续
C#-WinForm小游戏《双色球抽奖游戏》源码
中国福利彩票双色球游戏规则: 1、“双色球”彩票投注区分为红色球号码区和蓝色球号码区。 2、“双色球”每注投注号码由6个红色球号码和1个蓝色球号码组成。红色球号码从1--33中选择;蓝色球号码从1--16中选择。 功能描述: 1、点击“开始”,6个红球、1个蓝球根据规则随机生成不同的数,数据在不停地变换; 2、点击“结束”数据停止变换,6个红球和1个蓝球值固定。
用c#写的双色球摇奖器源码
刚学习C#练手时,自己写的一个小程序,主要技术在于随机数抽取的实现。是自创的方法。供学习交流


