您的位置:首页 > 编程语言 > C#

c#限时实验

2014-04-25 11:28 453 查看
一,材料说明:

中国福利彩票双色球游戏规则说明:双色球由红球和蓝球两部份组成,从33个红球号码(01~33)中选择6个,再从16个蓝球号码(01~16)中选择1个。

单注彩票号码生成说明:共7个号码;前6个为红球号码,不可重复,按升序排列;第7个号码为蓝球号码;

单注彩票数字示例说明: 2,4,8,10,22,33,10

中奖规则:红球计1元,篮球计10元;如开奖号码是7,11,16,18,21,22,2;投注金额是13,15,19,20,23,30,2. 则投注号码没有红色球相同,蓝球号码相同,因此中奖金额是10元

二,编程要求,如下图所示:





1,点击”开奖号码”按钮生成一注双色球号码(6个红球号码和一个篮球号码);

2,点击”从对话框获取数量”按钮,弹出对话窗口,输入数据并确定后,将数据返回到主窗口的文本框中;

3,点击”自动生成投注号码”按钮后,根据上述的数量,生成相应的多注号码组并添加到ListBox控件中(每次只能选择一项);

4,在ListBox中,每选择一项时,根据开奖规则显示中奖金额在下面的文本框中。

5,在主窗口左上角的标题栏,显示自己的班级姓名;

三,编程提示:

1,不重复的数据,可以使用HashSet<int>存储数据;也可以定义int[],自己判断是否重复;

2,排序可以使用Array.Sort方法。对于HashSet<int>来说,ToArray方法将其转换为int[];

3,每选中一项生成中奖金额,在ListBox的SelectedIndexChanged事件中编写代码;取当前项对应的字符串:SelectedItem.ToString;

4,使用字符串的Split方法,取出逗号分隔的字符串中数据;

四,评分规则:

1,功能完成,无Bug, 100分;

2,功能完成,有Bug, 90-95分;

3,部分功能未完成,70-89分;

4,在规定时间内,提交成功,无论是否编写代码,50分以上;

5,在规定时间内,提交不成功;从提交时间开始的20分钟内,发邮件到教师邮箱 lhx666@scau.edu.cn, 根据完成功能情况酌情给分,最高成绩80分;超出20分钟再发邮件视为无效;

6,无特殊原因,未提交作业,0分;

7,代码雷同,视为作弊,最高成绩50分;

-----------------------------------------------------------------------------------------------------------------

华丽丽的分割线

-----------------------------------------------------------------------------------------------------------------

1:Form1.cs

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.Collections;
namespace class3
{
public partial class Form1 : Form
{
private int num;//个数
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
if (form2.ShowDialog() == DialogResult.OK)
{
this.textBox2.Text = form2.Number.ToString();
this.num = form2.Number;
}

}

private void button2_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
Hashtable ht = new Hashtable();
ArrayList akeys = new ArrayList();
Random rm = new Random();
int Flag = 1;
for(int j=0;j<this.num+1;j++){
for (int i = 0; ht.Count < 6; i++)
{
int rValue = rm.Next(33)+1;
if (!ht.ContainsValue(rValue))
{
ht.Add(rValue, rValue);
akeys.Add(rValue);
}
}

akeys.Sort();
int bValue = rm.Next(16)+1;//蓝球
akeys.Add(bValue );
string array="";
foreach (int skey in akeys)
{
array += skey.ToString()+",";
}
if (Flag == 1)
{
Flag=0;
this.textBox1.Text=array.ToString();
}
else
this.listBox1.Items.Add(array);

ht.Clear();
akeys.Clear();

}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//中奖规则:红球计1元,篮球计10元;
string selected= listBox1.SelectedItem.ToString();//被选择的项的具体内容
string[] num=selected.Split(new string[]{","},StringSplitOptions.None);//分隔符分开
//取中奖号码
string trueString=textBox1.Text;
string[] trueNum=trueString.Split(new string[]{","},StringSplitOptions.None);
//把中奖号码用ArrayList存起来,方便下面查找
ArrayList aNum=new ArrayList();
foreach (string a in trueNum)
aNum.Add(a);
int sum = 0;
for (int i = 0; i < 6; i++)
{
if(aNum.Contains(num[i]))
sum += 1;
}
if(num[6]==trueNum[6])
sum += 10;
this.textBox3.Text = sum.ToString();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}


界面:



2:Form2.cs

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;
namespace class3
{
public partial class Form2 : Form
{
//读、写数值个数
private int number;
public int Number
{
get { return number; }
set
{
if (value > 0)
number = value;
else
number = 0;
}
}
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Number = int.Parse(this.textBox1.Text);
this.DialogResult = DialogResult.OK;
}
private void button2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}


界面:



演示:



Author:June
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息