一、前言

这是我在大一第一学期C#的课程设计,要求编写一个模拟双色球彩票的控制台应用程序,用以实现简单的模拟选购彩票。

1、双色球购号号码生成:

1.系统购号:通过“随机数”产生双色球的各个号码,通过“数组”保存所生成的每一注号码,并生成系统购号记录。
2.手动购号:用户输入要购买的数字,通过“数组”保存所生成的每一注号码,并生成手动购号记录。

2、双色球开奖号码生成:

同每一注系统购号号码生成原理相同。

3、开奖对比:

将开奖结果与手动、系统购号记录进行对比,输出中奖结果并打印。
中奖规则

二、课题介绍

1、功能要求

(1)用 C#语言实现程序设计;
(2)利用结构体进行相关信息处理;
(3)良好的人机互交;
(4)需求设计,满足功能和非功能需求;
(5)界面设计,内容编排合理,布局合理,易于操作;
(6)结构设计,程序设计合理,逻辑结构清晰,处理流程正确,功能划分明确;
(7)项目设计文档,项目架构设计正确,详细描述数据库设计和项目功能模块设计;
(8)编码可读性,代码编写遵循规范,注释清晰,可读性强;
(9)项目调试,能够熟练调试程序;
(10)项目测试,能够熟练测试程序,找到bug并进行修正;
(11)项目整体运行情况,项目程序能成功运行,无重大Bug,出现Bug也能当场调试通过;
(12)项目答辩,项目讲解较为清晰,能正确回答老师的提问。

2、主要任务

(1)运用本学期所学的控制台应用程序;
(2)熟练掌握数组、随机数、方法、类等;
(3)编写代码;
(4)程序分析与调试。

3、运行环境

(1)Win7 /Win10系统;
(2)Visual Studio 2019 开发环境;

4、开发语言

C#语言。

三、用到的按键

功能选择: QW ER
数字选择:0123456789
功能确认:Enter

四、程序设计

1、系统流程

双色球流程图

2、特色功能的实现

  • 产生模拟奖池;
  • 生成自定义数据库;
  • 打印数据,读取数据;
  • 界面输出优化;
  • 保护用户隐私;
  • 程序结束后可继续查看中奖记录等。

3、运行展示

运行展示

4、数据保存设计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1次设计.
用普通数据记录
第【01】注:红色球:01 02 03 04 05 06 蓝色球:07 【系统购号】时间:2019.06.12 22:02:01
第【02】注:红色球:06 14 15 22 29 32 蓝色球:11 【手动购号】时间:2019.06.12 22:02:07
2次设计.
去掉固定字符
01_01_02_03_04_05_06_07_系统购号_2019.06.12 22:02:01
02_06_14_15_22_29_32_11_手动购号_2019.06.12 22:02:07
3次设计.
用标记值 _
01_01_02_03_04_05_06_07_2019.06.12 22:02:01
02_06_14_15_22_29_32_11_2019.06.12 22:02:07
4次设计.
用标记值 X R B T
X01R010203040506B07T2019.06.12 22:02:01
X02R061415222932B11T2019.06.12 22:02:07

五、核心代码

Program.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:Program.cs
// description:程序入口文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Program
{
public static void Main(string[] args)
{
Class1 myclass1_guize = new Class1();
Class3 myclass3_xuanhao = new Class3();
Class4 myclass4_kaijiang = new Class4();
myclass4_kaijiang.ShanChuXiTongWenJian();//删除程序启动前创建的系统购号记录
myclass4_kaijiang.ShanChuShouDongWenJian();//删除程序启动前创建的手动购号记录
Console.WriteLine(" @摘繁华 版权所有");
Console.WriteLine("你好!欢迎你进入摘繁华的模拟双色球程序!\n");
Console.WriteLine("===================================================程序开始===================================================");
int biaojizhi = 1;
while (biaojizhi != 0)
{
Console.WriteLine("请选择:1.不了解双色球规则,查看规则【Q/q】; \t2.了解双色球规则,进入模拟【W/w】; \t3.结束本程序【E/e】;");
string xuanze =Console.ReadLine().ToUpper();
switch (xuanze)
{
case "Q":
Console.WriteLine("你选择了查看双色球规则;");
myclass1_guize.GuiZe();
break;
case "W":
Console.WriteLine("你选择了进入模拟;");
myclass3_xuanhao.HaoMa();
break;
case "E":
Console.WriteLine("你选择了结束程序!");
biaojizhi = 0;
break;
default:
Console.WriteLine("你的输入有误,请重新选择!");
break;
}
}
Console.WriteLine("===================================================程序结束===================================================");
Console.WriteLine("程序结束,按任意键退出。");
Console.WriteLine(" @摘繁华 版权所有");
Console.ReadKey(true);
}
}
}

1_游戏规则.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:1_游戏规则.cs
// description:游戏规则文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class1
{
public void GuiZe()
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("一、玩法及说明\n" +
"双色球投注区分为红球号码区和蓝球号码区,红球号码范围为01~33,蓝球号码范围为01~16。双色球每期从33个红球中\n" +
"开出6个号码,从16个蓝球中开出1个号码作为中奖号码,双色球玩法即是竞猜开奖号码的6个红球号码和1个蓝球号码,顺\n" +
"序不限。");
Console.WriteLine("二、设奖及中奖\n" +
"|------|-----------|--------|-----------------------------------------------------------------|--------|\n" +
"| | 中奖条件 | | | |\n" +
"| 奖级 |-----------|中奖说明| 单注奖金 |单注赔率|\n" +
"| | 红球 |蓝球| | | |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"| | | | | 当奖池资金低于1亿元时,奖金总额为当期高等奖奖金的75%与奖池中| |\n" +
"| | | | |累积的奖金之和,单注奖金按注均分,单注最高限额封顶500万元。 | |\n" +
"| | | | | 当奖池资金高于1亿元(含)时,奖金总额包括两部分,一部分为当期 | |\n" +
"|一等奖|RRRRRR| B | 中6+1 |高等奖奖金的55 % 与奖池中累积的奖金之和,单注奖金按注均分,单注最| —— |\n" +
"| | | | |高限额封顶500万元;另一部分为当期高等奖奖金的20%,单注奖金按注均分| |\n" +
"| | | | |,单注最高限额封顶500万元。 | |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"|二等奖|RRRRRR| | 中6+0 | 当期高等奖奖金的25% | —— |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"|三等奖|RRRRR | B | 中5+1 | 单注奖金额固定为3000元 | 1:1500 |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"| |RRRRR | | 中5+0 | | |\n" +
"|四等奖|------|----|--------| 单注奖金额固定为200元 | 1:100 |\n" +
"| |RRRRR | B | 中4+1 | | |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"| |RRRR | | 中4+0 | | |\n" +
"|五等奖|------|----|--------| 单注奖金额固定为10元 | 1:5 |\n" +
"| |RRR | B | 中3+1 | | |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|\n" +
"| |RR | B | 中2+0 | | |\n" +
"| |------|----|--------| | |\n" +
"|六等奖|R | B | 中1+1 | 单注奖金额固定为5元 | 1:2.5 |\n" +
"| |------|----|--------| | |\n" +
"| | | B | 中0+1 | | |\n" +
"|------|------|----|--------|-----------------------------------------------------------------|--------|");
Console.WriteLine("注:\n" +
"1、高等奖奖金=奖金总额-固定奖奖金。\n" +
"2、当奖池奖金超过1亿元(含)时,下期一等奖奖金总额包括两部分,一部分为高等奖奖金的55 % 与奖池奖金之和,单注\n" +
"奖金按注均分,封顶500万元;另一部分为高等奖奖金的20 %,单注奖金按注均分,封顶500万元。 \n" +
"3、奖池奖金在1亿元以下时,单注奖金封顶500万元。");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("你已查看完双色球规则!\n");
}
}
}

2_账户资金.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:2_账户资金.cs
// description:账户资金文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
public class Class2_ZiJi
{
public void ZiJin_shouci()
{
Class2_ZiJinBianHua myclass_chushiyue = new Class2_ZiJinBianHua();
Console.WriteLine("为了你的首次体验,系统已为你赠送100元用于购买双色球,你的账户初始余额为:{0:C}元;\n", FormatMoney(myclass_chushiyue.ChuShiYuE(100)));//输出初始余额
}
//手动存取金额
public void ZiJin_cunqu()
{
Class2_ZiJinBianHua myclass_cunqu = new Class2_ZiJinBianHua();
Console.WriteLine("请输入你的账户存取额(正为存入,负为取出):");
int cunruzhi = int.Parse(Console.ReadLine());
if (cunruzhi >= 0)//输出账户存入的存入额
{
Console.WriteLine("\t已存入金额为:{0:C}元;", FormatMoney(Math.Abs(cunruzhi)));
}
else
{
if (Math.Abs(cunruzhi) > myclass_cunqu.YuE)
{
Console.WriteLine("\t取出金额不能大于账户的余额:{0}元;",FormatMoney(myclass_cunqu.YuE));
}
else
{
Console.WriteLine("\t已取出金额为:{0:C}元;", FormatMoney(Math.Abs(cunruzhi)));
}
}
//输出账户余额
myclass_cunqu.CunQu(cunruzhi);
Console.WriteLine("\t你的账户的余额为:{0:C}元;", FormatMoney(myclass_cunqu.YuE));
}
//格式化金额
public string FormatMoney(int money)
{
if (money.ToString().Length > 4)
{
string fenge1 = money.ToString().Substring(0, money.ToString().Length - 4);
string fenge2 = money.ToString().Substring(money.ToString().Length - 4, 4);
if (fenge1.Length > 4)
{
return FormatMoney(Convert.ToInt32(fenge1)) + "," + fenge2;
}
else
{
return fenge1 + "," + fenge2;
}
}
else
{
return money.ToString();
}
}
//购号花费金额
public void ZiJin_qu(int zhushu)
{
Class2_ZiJinBianHua myclass_qu = new Class2_ZiJinBianHua();
int cunruzhi = -2 * zhushu;
if (cunruzhi < 0)//输出账户存入的存入额
{
Console.WriteLine("\t已花费金额为:{0:C}元;", FormatMoney(Math.Abs(cunruzhi)));
}
//输出账户余额
myclass_qu.CunQu(cunruzhi);
Console.WriteLine("\t你的账户的余额为:{0:C}元;", FormatMoney(myclass_qu.YuE));
}
//中奖存入金额
public void ZiJin_cun(int cunruzhi)
{
Class2_ZiJinBianHua myclass_cun = new Class2_ZiJinBianHua();
if (cunruzhi > 0)//输出账户存入的存入额
{
Console.WriteLine("\t你的账户已存入金额为:{0:C}元;", FormatMoney(cunruzhi));
}
//输出账户余额
myclass_cun.CunQu(cunruzhi);
Console.WriteLine("\t你的账户的余额为:{0:C}元;", FormatMoney(myclass_cun.YuE));
}
}
public class Class2_ZiJinBianHua
{
public int ChuShiYuE(int chushiyue)//接受初始余额
{
YuE = chushiyue;
return YuE;
}
public void CunQu(int cunqu) //接受存钱
{
YuE = YuE + cunqu;
}
private static int yue; //余额
public int YuE
{
get
{
return yue;
}
set
{
if (value >= 0)
yue = value;
}
}
}
}

3_0模拟选号.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:3_0模拟选号.cs
// description:模拟选号文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class3
{
public void HaoMa()
{
Class3_1 myclass3_1_xitong = new Class3_1();
Class3_2 myclass3_2_shoudong = new Class3_2();
Class3_3 myclass3_3_kaijiang = new Class3_3();
Console.WriteLine();
Console.WriteLine(" =======================================模拟双色球开始=======================================");
Class2_ZiJi myclass2_zijin = new Class2_ZiJi();
myclass2_zijin.ZiJin_shouci();//账户资金
int biaojizhi = 1;
while (biaojizhi != 0)
{
Console.WriteLine("请选择:1.系统购号【Q/q】; \t2.手动购号【W/w】;\t3.对已购双色球开奖【E/e】; \t4.返回主菜单【R/r】;");
string xuanze = Console.ReadLine().ToUpper();
switch (xuanze)
{
case "Q":
Console.WriteLine("你选择了系统购号;");
myclass3_1_xitong.XiTong();
break;
case "W":
Console.WriteLine("你选择了手动购号;");
myclass3_2_shoudong.ShouDong();
break;
case "E":
Console.WriteLine("你选择了对已购买双色球开奖;");
myclass3_3_kaijiang.ZhongJiang();
break;
case "R":
Console.WriteLine("你选择了返回主菜单;");
biaojizhi = 0;
break;
default:
Console.WriteLine("你的输入有误,请重新输入!");
break;
}
}
Console.WriteLine(" =======================================模拟双色球结束=======================================");
Console.WriteLine();
}
}
}

3_1系统购号.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:3_1系统购号.cs
// description:系统购号文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class3_1
{
Class2_ZiJi myclass2_zijin = new Class2_ZiJi();
Class2_ZiJinBianHua myclass2_yue = new Class2_ZiJinBianHua();
Class4 XiTong_myclass4 = new Class4();
Random random = new Random();
private int[] xitonggouhao = new int[7];
public void XiTong()//系统购买
{
Console.WriteLine();
Console.WriteLine(" =============================系统购号开始=============================");
Console.WriteLine("请输入你要购买几注双色球:");
int zhushu = int.Parse(Console.ReadLine());//定义购买双色球的注数
if ((decimal)zhushu * 2 > myclass2_yue.YuE)//判断余额
{
while ((decimal)zhushu * 2 > myclass2_yue.YuE)
{
Console.WriteLine("\t你的账户余额不够购买{0}注双色球,请充值;", zhushu);
myclass2_zijin.ZiJin_cunqu();
Console.WriteLine("请输入你要购买几注双色球:");
zhushu = int.Parse(Console.ReadLine());
}
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t系统正在为你购买【{0}】注双色球...", zhushu);
Console.ForegroundColor = ConsoleColor.Gray;
for (int zhushujishu = 1; zhushujishu <= zhushu; zhushujishu++)
{
Console.Write("第【{0,2}】注:", zhushujishu);
Red();
Blue();
Console.Write("\t【系统购号】");
Console.Write("时间:{0}", DateTime.Now.ToString());
XiTong_myclass4.XiTongGouHaoJiLu(zhushujishu, xitonggouhao);
Console.WriteLine();
}
Console.WriteLine("\t系统已为你完成购买【{0,2}】注双色球!", zhushu);
myclass2_zijin.ZiJin_qu(zhushu);
Console.WriteLine(" =============================系统购号结束=============================");
Console.WriteLine(" (你可以选择继续购号或开奖)");
Console.WriteLine();
}
private void Red()//红色球
{
int[] zuheredshuzi = new int[6];//定义红色球数组
for (int everyzhushushuzi = 0; everyzhushushuzi < zuheredshuzi.Length; everyzhushushuzi++)
{
int redshuzi = random.Next(1, 34);//产生随机数字(1-33)
redshuzi = RedChongFu(everyzhushushuzi, zuheredshuzi, redshuzi);
zuheredshuzi[everyzhushushuzi] = redshuzi;
}
RedShengXu(zuheredshuzi);
RedShuChu(zuheredshuzi);
}
private int RedChongFu(int everyzhushushuzi,int[] zuheredshuzi,int redshuzi)//红色球_重复数字检验
{
for (int chongfu = 0; chongfu < everyzhushushuzi; chongfu++)
{
while (redshuzi == zuheredshuzi[chongfu])
{
redshuzi = random.Next(1, 34);
redshuzi = RedChongFu(everyzhushushuzi, zuheredshuzi, redshuzi);
}
}
return redshuzi;
}
private void RedShengXu(int[] zuheredshuzi)//红色球_升序
{
for (int i = 0; i < zuheredshuzi.Length - 1; i++)
{
for (int j = 0; j < zuheredshuzi.Length - 1 - i; j++)
{
if (zuheredshuzi[j] > zuheredshuzi[j + 1])
{
int max = zuheredshuzi[j];
zuheredshuzi[j] = zuheredshuzi[j + 1];
zuheredshuzi[j + 1] = max;
}
}
}
}
private void RedShuChu(int[] zuheredshuzi)//红色球_输出
{
Console.Write("红色球:");
for (int shuchu = 0; shuchu < zuheredshuzi.Length; shuchu++)
{
System.Threading.Thread.Sleep(50);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0,2:D2} ", zuheredshuzi[shuchu]);
xitonggouhao[shuchu] = zuheredshuzi[shuchu];
Console.ForegroundColor = ConsoleColor.Gray;
}
}
private void Blue()//蓝色球
{
int blueshuzi = random.Next(1, 17);//产生随机数字(1-16)
Console.Write("蓝色球:");//输出
System.Threading.Thread.Sleep(50);
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("{0,2:D2} ", blueshuzi);
xitonggouhao[6] = blueshuzi;
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}

3_2手动购号.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:3_2手动购号.cs
// description:手动购号文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class3_2
{
Class2_ZiJi myclass2_zijin = new Class2_ZiJi();
Class2_ZiJinBianHua myclass2_yue = new Class2_ZiJinBianHua();
Class4 ShouDong_myclass4 = new Class4();
private int[] shoudonggouhao = new int[7];
public void ShouDong()//手动购买
{
Console.WriteLine();
Console.WriteLine(" =============================手动购号开始=============================");
Console.WriteLine("请输入你要购买几注双色球:");
int zhushu = int.Parse(Console.ReadLine());
if ((decimal)zhushu * 2 > myclass2_yue.YuE)//判断余额
{
while ((decimal)zhushu * 2 > myclass2_yue.YuE)
{
Console.WriteLine("\t你的账户余额不够购买{0}注双色球,请充值;", zhushu);
myclass2_zijin.ZiJin_cunqu();
Console.WriteLine("请输入你要购买几注双色球:");
zhushu = int.Parse(Console.ReadLine());
}
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t你正在手动购买【{0}】注双色球...", zhushu);
Console.ForegroundColor = ConsoleColor.Gray;
for (int zhushujishu = 1; zhushujishu <= zhushu; zhushujishu++)//对注数进行计数
{
int[] allredshuzi = new int[6];//定义红色球数字组合后的数组
int blueshuzi = 0;//定义蓝色球数字
Red(zhushujishu, allredshuzi);//调用红色球方法
blueshuzi = Blue(zhushujishu);//调用蓝色球方法
Console.Write("第【{0,2}】注:", zhushujishu);
ShuChu(zhushujishu, allredshuzi, blueshuzi);//组合输出双色球
Console.Write("\t【手动购号】");
Console.Write("时间:{0}", DateTime.Now.ToString());
ShouDong_myclass4.ShouDongGouHaoJiLu(zhushujishu, shoudonggouhao);
Console.WriteLine();
}
Console.WriteLine("\t你已完成手动购买【{0,2}】注双色球!", zhushu);
myclass2_zijin.ZiJin_qu(zhushu);
Console.WriteLine(" =============================手动购号结束=============================");
Console.WriteLine(" (你可以选择继续购号或开奖)");
Console.WriteLine();
}
private void Red(int zhushujishu, int[] allredshuzi)//红色球
{
Console.WriteLine("请输入第[{0,2}]注你要选择的(1-33之间的)6个[红色球]号码:", zhushujishu);
for (int everyzhushushuzi = 0; everyzhushushuzi < allredshuzi.Length; everyzhushushuzi++)
{
Console.Write("第{0}位:", everyzhushushuzi + 1);
int redshuzi = int.Parse(Console.ReadLine());
redshuzi = RedPanDuan(everyzhushushuzi, redshuzi, allredshuzi); //红色球_判断
allredshuzi[everyzhushushuzi] = redshuzi;
}
RedShengXu(allredshuzi);//调用红色球_升序的方法
}
private int RedPanDuan(int everyzhushushuzi, int redshuzi, int[] allredshuzi)
{
redshuzi = RedFanWei(everyzhushushuzi, redshuzi);//调用红色球_范围的方法
redshuzi = RedChongFu(everyzhushushuzi, redshuzi, allredshuzi);//调用红色球_重复数字检验的方法
return redshuzi;
}
private int RedFanWei(int everyzhushushuzi, int redshuzi)//红色球_范围
{
while (!(redshuzi >= 1 && redshuzi <= 33))
{
if (!(redshuzi >= 1 && redshuzi <= 33))//判断输入数字是否在(1-33)范围内,若不是,重新输入,若是,赋值
{
Console.Write("第{0}位数:(输入范围错误![{1}]超出了输入范围,请重新输入(1-33之间)的数)", everyzhushushuzi + 1, redshuzi);
redshuzi = int.Parse(Console.ReadLine());
redshuzi = RedFanWei(everyzhushushuzi, redshuzi);
break;
}
}
return redshuzi;
}
private int RedChongFu(int everyzhushushuzi, int redshuzi, int[] allredshuzi)//红色球_重复数字检验
{
int xuhao = 0;
int chongfubiaojizhi = 0;
for (int i = 0; i < everyzhushushuzi; i++)
{
if (redshuzi == allredshuzi[i])
{
xuhao = i;
chongfubiaojizhi++;
}
}
if (chongfubiaojizhi != 0)
{
int biaojizhi = 1;
while (biaojizhi != 0)
{
string chongfutishi = "除";
for (int shuchu = 0; shuchu < everyzhushushuzi; shuchu++)
{
string chongfushu = "";
for (int t = 0; t <= shuchu; t++)
{
chongfushu = "[" + Convert.ToString(allredshuzi[t]) + "]";
}
chongfutishi = chongfutishi + chongfushu;
}
Console.Write("第{0}位数:(输入重复错误!你购买的第{1}位数字已存在数字{2},请重新输入(1-33之间)({3})的数)", everyzhushushuzi + 1, xuhao + 1, redshuzi, chongfutishi);
redshuzi = int.Parse(Console.ReadLine());
redshuzi = RedPanDuan(everyzhushushuzi, redshuzi, allredshuzi);
biaojizhi = 0;
}
}
return redshuzi;
}
private void RedShengXu(int[] allredshuzi)//红色球_升序
{
for (int i = 0; i < allredshuzi.Length - 1; i++)
{
for (int j = 0; j < allredshuzi.Length - 1 - i; j++)
{
if (allredshuzi[j] > allredshuzi[j + 1])
{
int max = allredshuzi[j];
allredshuzi[j] = allredshuzi[j + 1];
allredshuzi[j + 1] = max;
}
}
}
}
private int Blue(int zhushujishu)//蓝色球
{
Console.WriteLine("请输入第[{0,2}]注你要选择的(1-16之间的)1个[蓝色球]号码:", zhushujishu);
Console.Write("第1位:");
int blueshuzi = int.Parse(Console.ReadLine());
blueshuzi = BlueFanWei(blueshuzi);//调用蓝色球_范围的方法
return blueshuzi;
}
private int BlueFanWei(int blueshuzi)//蓝色球_范围
{
while (!(blueshuzi >= 1 && blueshuzi <= 16))//判断输入数字是否在(1-16)范围内,若是,返回值,若不是,重新输入
{
if (!(blueshuzi >= 1 && blueshuzi <= 16))
{
Console.Write("第1位数:(输入范围错误!请重新输入(1-16之间)的数)");
blueshuzi = int.Parse(Console.ReadLine());
}
}
return blueshuzi;
}
private void ShuChu(int zhushujishu, int[] allredshuzi, int blueshuzi)//总输出
{
ShuChuRed(allredshuzi);
ShuChuBlue(zhushujishu, blueshuzi);
}
private void ShuChuRed(int[] allredshuzi)//红色球_输出
{
Console.Write("红色球:");
for (int shuchu = 0; shuchu < allredshuzi.Length; shuchu++)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0,2:D2} ", allredshuzi[shuchu]);
shoudonggouhao[shuchu] = allredshuzi[shuchu];
Console.ForegroundColor = ConsoleColor.Gray;
}
}
private void ShuChuBlue(int zhushujishu, int blueshuzi)//蓝色球_输出
{
Console.Write("蓝色球:");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("{0,2:D2} ", blueshuzi);
shoudonggouhao[6] = blueshuzi;
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}

3_3模拟开奖.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:3_3模拟开奖.cs
// description:模拟开奖文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class3_3
{
/*------------中奖入口-----------判断是否开奖(判断记录存在)------------开奖结果------------查找数据-------------*/
private readonly string duquming_kaijiang_xitong = "系统购号";
private readonly string duquming_kaijiang_shoudong = "手动购号";
private bool chazhaojilu;
private int hangshu;
private int monijiangchi;//模拟奖池
private int zong_zhongjiang = 0;//中奖总数
private int yi_zhongjiang = 0;//一等奖总数
private int er_zhongjiang = 0;//二等总数
private int san_zhongjiang = 0;//三等总数
private int si_zhongjiang = 0;//四等总数
private int wu_zhongjiang = 0;//五等总数
private int liu_zhongjiang = 0;//六等总数
public int[] kaijianghong = new int[7];
private string zhongjiangdengji;
private int zhongjiangjine;
private int zhongjiangjine_zong;
Class5 myclass5_duqu = new Class5();
Class2_ZiJi myclass2_zijin = new Class2_ZiJi();
/*--------------中奖入口----------------*/
public void ZhongJiang()
{
PanDuan_kaijiang(); //判断是否开奖
//判断记录存在、开奖结果
if (chazhaojilu) { ChaZhao_shuju(); }//记录存在时查找数据
ShanChu_gouhaojilu();//删除购号记录
}
Class4 myclass4_dayin = new Class4();
/*--------------判断是否开奖----------------*/
private void PanDuan_kaijiang()
{
myclass4_dayin.ShanChuKaiJiangWenJian();//删除开奖前创建的模拟开奖历史记录
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t正在判断是否开奖...");
Console.ForegroundColor = ConsoleColor.Gray;
System.Threading.Thread.Sleep(500);
chazhaojilu = myclass5_duqu.ChaZhao();
PanDuan_jilucunzai(chazhaojilu);//判断记录存在
}
/*--------------判断记录存在----------------*/
private void PanDuan_jilucunzai(bool panduancunzai)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\t正在判断是否存在购号记录...");
Console.ForegroundColor = ConsoleColor.Gray;
System.Threading.Thread.Sleep(500);
if (panduancunzai)
{
Console.Write("\t存在购号记录,即将开奖!\n");
KaiJiang();//存在购号记录后开奖
}
else
{
Console.Write("\t你没有任何形式的购号记录,请先购号后开奖!\n");
Console.WriteLine();
}
Console.ForegroundColor = ConsoleColor.Gray;
}
/*--------------开奖结果----------------*/
public void KaiJiang()//产生开奖号
{
Console.WriteLine();
Console.WriteLine(" ================模拟开奖开始================");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t正在产生开奖号码...");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("【开奖号码】");
Red();
Blue();
Console.Write("\t【模拟开奖】");
Console.Write("时间:{0}\n", DateTime.Now.ToString());
Console.WriteLine("\t开奖号码已产生!\n");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\t正在计算奖池金额...");
Console.ForegroundColor = ConsoleColor.Gray;
Random jiangchi = new Random();
monijiangchi = jiangchi.Next(56214873, 942746513);
System.Threading.Thread.Sleep(3000);
Console.Write("\t本次开奖奖池金额为:[{0}]元;\n", myclass2_zijin.FormatMoney(monijiangchi));
myclass4_dayin.MoNiKaiJiang(kaijianghong, myclass2_zijin.FormatMoney(monijiangchi));//打印模拟开奖记录
Console.WriteLine(" ================模拟开奖结束================");
Console.WriteLine();
}
private void Red()//红色球
{
int[] zuheredshuzi = new int[6];//定义红色球数组
Random red = new Random();
for (int everyzhushushuzi = 0; everyzhushushuzi < zuheredshuzi.Length; everyzhushushuzi++)
{
int redshuzi = red.Next(1, 34);//产生随机数字(1-33)
redshuzi = RedChongFu(everyzhushushuzi, zuheredshuzi, redshuzi);
zuheredshuzi[everyzhushushuzi] = redshuzi;
}
RedShengXu(zuheredshuzi);
RedShuChu(zuheredshuzi);
}
private int RedChongFu(int everyzhushushuzi, int[] zuheredshuzi, int redshuzi)//红色球_重复数字检验
{
Random redchongfu = new Random();
for (int chongfu = 0; chongfu < everyzhushushuzi; chongfu++)
{
while (redshuzi == zuheredshuzi[chongfu])
{
redshuzi = redchongfu.Next(1, 34);
redshuzi = RedChongFu(everyzhushushuzi, zuheredshuzi, redshuzi);
}
}
return redshuzi;
}
private void RedShengXu(int[] zuheredshuzi)//红色球_升序
{
for (int i = 0; i < zuheredshuzi.Length - 1; i++)
{
for (int j = 0; j < zuheredshuzi.Length - 1 - i; j++)
{
if (zuheredshuzi[j] > zuheredshuzi[j + 1])
{
int max = zuheredshuzi[j];
zuheredshuzi[j] = zuheredshuzi[j + 1];
zuheredshuzi[j + 1] = max;
}
}
}
}
private void RedShuChu(int[] zuheredshuzi)//红色球_输出
{
Console.Write("红色球:");
for (int shuchu = 0; shuchu < zuheredshuzi.Length; shuchu++)
{
System.Threading.Thread.Sleep(500);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0,2:D2} ", zuheredshuzi[shuchu]);
kaijianghong[shuchu] = zuheredshuzi[shuchu];
Console.ForegroundColor = ConsoleColor.Gray;
}
}
private void Blue()//蓝色球
{
Random blue = new Random();
System.Threading.Thread.Sleep(500);
int blueshuzi = blue.Next(1, 17);//产生随机数字(1-16)
Console.Write("蓝色球:");//输出
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("{0,2:D2} ", blueshuzi);
kaijianghong[6] = blueshuzi;
Console.ForegroundColor = ConsoleColor.Gray;
}
/*--------------查找数据----------------*/
public void ChaZhao_shuju()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t正在查找数据,请稍候...");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" ========查看中奖开始========");
ChaZhao_shuju_xitong(); //查找数据_系统
ChaZhao_shuju_shoudong();//查找数据_手动
if (zong_zhongjiang == 0)
{
Console.WriteLine("\t抱歉,你没有中奖!");
}
else
{
Console.WriteLine("\t你共中奖[{0}]注,获得总奖金:[{7}]元!其中:\n" +
"\t一等奖[{1}]注;" +
"二等奖[{2}]注;" +
"三等奖[{3}]注;" +
"四等奖[{4}]注;" +
"五等奖[{5}]注;" +
"六等奖[{6}]注;", zong_zhongjiang, yi_zhongjiang, er_zhongjiang, san_zhongjiang, si_zhongjiang, wu_zhongjiang, liu_zhongjiang, myclass2_zijin.FormatMoney(zhongjiangjine_zong));
}
myclass2_zijin.ZiJin_cun(zhongjiangjine_zong);
myclass4_dayin.MoNiKaiJiang_zhongjiang_jine_zong(zong_zhongjiang, yi_zhongjiang, er_zhongjiang, san_zhongjiang, si_zhongjiang, wu_zhongjiang, liu_zhongjiang, myclass2_zijin.FormatMoney(zhongjiangjine_zong));
Console.WriteLine(" ========查看中奖结束========");
zong_zhongjiang = 0;//总中奖数清零
yi_zhongjiang = 0;//一等奖总数清零
er_zhongjiang = 0;//二等总数清零
san_zhongjiang = 0;//三等总数清零
si_zhongjiang = 0;//四等总数清零
wu_zhongjiang = 0;//五等总数清零
liu_zhongjiang = 0;//六等总数清零
zhongjiangjine_zong = 0;//总中奖金额清零
}
public void ChaZhao_shuju_xitong()//查找数据_系统
{
bool xitong_cunzai = myclass5_duqu.ChaZhao_xitong();//判断是否存在系统购号记录
if (xitong_cunzai)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t查找到系统购号数据,正在读取...");
Console.ForegroundColor = ConsoleColor.Gray;
DuQu_hangshu(duquming_kaijiang_xitong);
}
else
{
Console.WriteLine("\t你没有系统购号数据!");
}
}
public void ChaZhao_shuju_shoudong()//查找数据_手动
{
bool shoudong_cunzai = myclass5_duqu.ChaZhao_shoudong();//判断是否存在手动购号记录
if (shoudong_cunzai)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\t查找到手动购号数据,正在读取...");
Console.ForegroundColor = ConsoleColor.Gray;
DuQu_hangshu(duquming_kaijiang_shoudong);
}
else
{
Console.WriteLine("\t你没有手动购号数据!");
}
}
/*-----------------读取数据-------------判断数据---------------判断中奖----------------输出中奖-----------删除购号记录-----------*/
/*--------------读取数据----------------*/
public void DuQu_hangshu(string duquming)
{
//读取行数
hangshu = myclass5_duqu.DuQu_hang(duquming);
//判断数据
PanDuan_shuju(duquming);
}
/*--------------判断数据----------------*/
public void PanDuan_shuju(string duquming)
{
int red = 0;
int blue = 0;
int[] duqu = new int[7];
duqu = myclass5_duqu.DuQu_shuzi;
for (int everyhang = 1; everyhang <= hangshu; everyhang++)
{
//读取数据
myclass5_duqu.DuQu_shuju(everyhang, duquming);
for (int kaijianghong_weishu = 0; kaijianghong_weishu < kaijianghong.Length - 1; kaijianghong_weishu++)//开奖号数字
{
for (int duququ_weishu = 0; duququ_weishu < 6; duququ_weishu++)//读取号数字
{
if (kaijianghong[kaijianghong_weishu] == duqu[duququ_weishu])
{
red++;
}
}
}
if (kaijianghong[6] == duqu[6])
{
blue = 1;
}
PanDuan_zhongjiang(myclass5_duqu.DuQu_xuhao, red, blue, myclass5_duqu.DuQu_time, duqu, duquming);
red = 0;//对比之后红色计数归零
blue = 0;//对比之后蓝色计数归零
}
}
/*--------------判断中奖----------------*/
public void PanDuan_zhongjiang(int xuhao, int red, int blue, string time, int[] duqu, string duquming)
{
bool shuchu = false;
if (red == 6 && blue == 1)
{
zhongjiangdengji = "一";
zhongjiangjine = Convert.ToInt32(monijiangchi * 0.6);
if (monijiangchi >= 100000000)
{
zhongjiangjine = 5000000;
}
zong_zhongjiang++;
yi_zhongjiang++;
shuchu = true;
}
if (red == 6 && blue == 0)
{
zhongjiangdengji = "二";
zhongjiangjine = Convert.ToInt32(monijiangchi * 0.2);
if (monijiangchi >= 100000000)
{
zhongjiangjine = 500000;
}
zong_zhongjiang++;
er_zhongjiang++;
shuchu = true;
}
if (red == 5 && blue == 1)
{
zhongjiangdengji = "三";
zhongjiangjine = 3000;
zong_zhongjiang++;
san_zhongjiang++;
shuchu = true;
}
if ((red == 5 && blue == 0) || (red == 4 && blue == 1))
{
zhongjiangdengji = "四";
zhongjiangjine = 200;
zong_zhongjiang++;
si_zhongjiang++;
shuchu = true;
}
if ((red == 4 && blue == 0) || (red == 3 && blue == 1))
{
zhongjiangdengji = "五";
zhongjiangjine = 10;
zong_zhongjiang++;
wu_zhongjiang++;
shuchu = true;
}
if ((red == 2 && blue == 1) || (red == 1 && blue == 1) || (red == 0 && blue == 1))
{
zhongjiangdengji = "六";
zhongjiangjine = 5;
zong_zhongjiang++;
liu_zhongjiang++;
shuchu = true;
}
if (shuchu)
{
zhongjiangjine_zong += zhongjiangjine;
PanDuan_shuchu(xuhao, duqu, time, duquming);
Console.Write("\t[该注中了{0}等奖!获得奖金:{1}元;]", zhongjiangdengji, myclass2_zijin.FormatMoney(zhongjiangjine));
myclass4_dayin.MoNiKaiJiang_zhongjiang_jine(zhongjiangdengji, myclass2_zijin.FormatMoney(zhongjiangjine));
Console.WriteLine();
}
}
/*--------------中奖输出----------------*/
public void PanDuan_shuchu(int xuhao, int[] duqu, string time, string duquming)
{
Console.Write("第【{0,2}】注:红色球:", xuhao);
Console.ForegroundColor = ConsoleColor.Red;
for (int i = 0; i < 6; i++)
{
Console.Write("{0,2:D2} ", duqu[i]);
}
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("蓝色球:");
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("{0,2:D2}", duqu[6]);
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("\t【{0}】", duquming);
Console.Write("时间:{0}", time);
myclass4_dayin.MoNiKaiJiang_zhongjiang(xuhao, duqu, time, duquming);
}
/*--------------删除购号记录----------------*/
private void ShanChu_gouhaojilu()
{
myclass4_dayin.ShanChuXiTongWenJian();//删除上一次开奖前创建的系统购号记录
myclass4_dayin.ShanChuShouDongWenJian();//删除上一次开奖前创建的手动购号记录
}
}
}

4_打印数据.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:4_打印数据.cs
// description:打印数据文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class4
{
//系统购号记录
private readonly string XiTongFile = @"系统购号.txt";
public void ShanChuXiTongWenJian()
{
if (File.Exists(XiTongFile))
{
File.Delete(XiTongFile);//删除该文件
}
}
public void XiTongGouHaoJiLu(int zhushujishu, int[] shuangseqiu)
{
StreamWriter wenjian = File.AppendText(XiTongFile);
string xuhao = "X";
string red = "R";
string blue = "B";
string time = "T";
string gouhaojilu = xuhao + zhushujishu.ToString("D2") + red
+ shuangseqiu[0].ToString("D2") + shuangseqiu[1].ToString("D2") + shuangseqiu[2].ToString("D2")
+ shuangseqiu[3].ToString("D2") + shuangseqiu[4].ToString("D2") + shuangseqiu[5].ToString("D2")
+ blue + shuangseqiu[6].ToString("D2") + time + DateTime.Now.ToString();
wenjian.WriteLine(gouhaojilu);
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
//手动购号记录
private readonly string ShouDongFile = @"手动购号.txt";
public void ShanChuShouDongWenJian()
{
if (File.Exists(ShouDongFile))
{
File.Delete(ShouDongFile);//删除该文件
}
}
public void ShouDongGouHaoJiLu(int zhushujishu, int[] shuangseqiu)
{
StreamWriter wenjian = File.AppendText(ShouDongFile);
string xuhao = "X";
string red = "R";
string blue = "B";
string time = "T";
string gouhaojilu = xuhao+zhushujishu.ToString("D2")+ red
+ shuangseqiu[0].ToString("D2")+ shuangseqiu[1].ToString("D2")+ shuangseqiu[2].ToString("D2")
+ shuangseqiu[3].ToString("D2")+ shuangseqiu[4].ToString("D2")+ shuangseqiu[5].ToString("D2")
+blue+ shuangseqiu[6].ToString("D2") + time + DateTime.Now.ToString();
wenjian.WriteLine(gouhaojilu);
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
//模拟开奖记录
private readonly string KaiJiangFile = @"模拟开奖.txt";
public void ShanChuKaiJiangWenJian() {
if (File.Exists(KaiJiangFile))
{
File.Delete(KaiJiangFile);//删除该文件
}
}
public void MoNiKaiJiang(int[] kaijiang,string monijiangchi) {
StreamWriter wenjian = File.AppendText(KaiJiangFile);
string kong = " ";
string gouhaojilu = "【开奖号码】"
+ "红色球:" + kaijiang[0].ToString("D2") + kong + kaijiang[1].ToString("D2") + kong + kaijiang[2].ToString("D2")
+ kong + kaijiang[3].ToString("D2") + kong + kaijiang[4].ToString("D2") + kong + kaijiang[5].ToString("D2") + kong
+ "蓝色球:" + kaijiang[6].ToString("D2");
wenjian.Write("{0}", gouhaojilu);
wenjian.Write("\t【模拟开奖】");
wenjian.Write("时间:{0}", DateTime.Now.ToString());
wenjian.Write("\t本次开奖奖池金额为:[{0}]元;\n", monijiangchi);
wenjian.WriteLine();
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
//模拟开奖中奖记录
public void MoNiKaiJiang_zhongjiang(int xuhao, int[] duqu, string time, string duquming)
{
StreamWriter wenjian = File.AppendText(KaiJiangFile);
wenjian.Write("第【{0,2}】注:红色球:", xuhao);
for (int i = 0; i < 6; i++)
{
wenjian.Write("{0,2:D2} ", duqu[i]);
}
wenjian.Write("蓝色球:");
wenjian.Write("{0,2:D2}", duqu[6]);
wenjian.Write("\t【{0}】", duquming);
wenjian.Write("时间:{0}", time);
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
//模拟开奖中奖金额记录
public void MoNiKaiJiang_zhongjiang_jine(string zhongjiangdengji, string zhongjiangjine)
{
StreamWriter wenjian = File.AppendText(KaiJiangFile);
wenjian.Write("\t[该注中了{0}等奖!获得奖金:{1}元;]", zhongjiangdengji, zhongjiangjine);
wenjian.WriteLine();
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
//模拟开奖中奖金额记录
public void MoNiKaiJiang_zhongjiang_jine_zong(int zong_zhongjiang, int yi_zhongjiang, int er_zhongjiang, int san_zhongjiang, int si_zhongjiang, int wu_zhongjiang, int liu_zhongjiang, string zhongjiangjine_zong)
{
StreamWriter wenjian = File.AppendText(KaiJiangFile);
wenjian.Write("\t你共中奖[{0}]注,获得总奖金:[{7}]元!其中:\n" +
"\t一等奖[{1}]注;" +
"二等奖[{2}]注;" +
"三等奖[{3}]注;" +
"四等奖[{4}]注;" +
"五等奖[{5}]注;" +
"六等奖[{6}]注;", zong_zhongjiang, yi_zhongjiang, er_zhongjiang, san_zhongjiang, si_zhongjiang, wu_zhongjiang, liu_zhongjiang, zhongjiangjine_zong);
wenjian.Flush();
wenjian.Close();
wenjian.Dispose();//释放对象
}
}
}

5_读取数据.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//======================================================================
// Copyright © 2018 摘繁华 All Rights Reserved.
// filename:5_读取数据.cs
// description:读取数据文件
// created by 摘繁华 at 2019/10/25
//======================================================================
namespace ConsoleApplication1
{
class Class5
{
//定义需要用到的变量
private readonly string duquming_xitong = @"系统购号";
private readonly string duquming_shoudong = @"手动购号";
private readonly string file_xitong = @"系统购号.txt";
private readonly string file_shoudong = @"手动购号.txt";
//查找文件
public bool ChaZhao()
{
bool zongchazhao = ChaZhao_xitong() || ChaZhao_shoudong();
return zongchazhao;
}
public bool ChaZhao_xitong()
{
return (File.Exists(file_xitong));
}
public bool ChaZhao_shoudong()
{
return (File.Exists(file_shoudong));
}
//获取行数
public int DuQu_hang(string duquming)
{
int hang = 0;
if (duquming == duquming_xitong)
{
using (StreamReader read = new StreamReader(file_xitong, Encoding.Default))
{
hang = read.ReadToEnd().Split('\n').Length - 1;
}
}
if (duquming == duquming_shoudong)
{
using (StreamReader read = new StreamReader(file_shoudong, Encoding.Default))
{
hang = read.ReadToEnd().Split('\n').Length - 1;
}
}
return hang;
}
//读取数据
public void DuQu_shuju(int hang, string duquming)
{
string[] tiqu = new string[4];
if (duquming == duquming_xitong)
{
string[] yuanshuju = File.ReadAllLines(file_xitong, Encoding.UTF8);
tiqu = yuanshuju[hang - 1].Split(new char[4] { 'X', 'R', 'B', 'T' });
ChaiFen(tiqu);
}
if (duquming == duquming_shoudong)
{
string[] yuanshuju = File.ReadAllLines(file_shoudong, Encoding.UTF8);
tiqu = yuanshuju[hang - 1].Split(new char[4] { 'X', 'R', 'B', 'T' });
ChaiFen(tiqu);
}
}
//定义开奖需要用到的数据
public int DuQu_xuhao;//拆分后的序号(int)
public int[] DuQu_shuzi = new int[7];//定义一个读取文件后赋值的数组,用于比较是否中奖
public string DuQu_time;//拆分后的时间(string)
//拆分
public void ChaiFen(string[] tiqu)
{
//拆分后的序号(int)
DuQu_xuhao = int.Parse(tiqu[1]);
//拆分后的红球(string)
string chai_red = tiqu[2];
int[] chaifen_red = new int[6];
chaifen_red = ChaiFenRed(chai_red);
//拆分后的蓝球(int)
int chaifen_blue = int.Parse(tiqu[3]);
//拆分后的时间(string)
DuQu_time = tiqu[4];
//转换数据类型
IntZhuanHuan(chaifen_red, chaifen_blue);
}
//继续拆分红球
private int[] ChaiFenRed(string chai_red)
{
int[] red = new int[6];
int t = 0;
for (int i = 0; i <= 5; i++)
{
red[i] = int.Parse(chai_red.Substring(t, 2));
t = t + 2;
}
return red;
}
//读取文件后赋值的数组赋值
private void IntZhuanHuan(int[] chaifen_red, int chaifen_blue)
{
for (int i = 0; i < 6; i++)
{
DuQu_shuzi[i] = chaifen_red[i];
}
DuQu_shuzi[6] = chaifen_blue;
}
}
}

六、最后

参考文献:

C# 文本文件的读写:
https://www.runoob.com/csharp/csharp-text-files.html;
C# 如何改变控制台输出字体颜色:
https://zhidao.baidu.com/question/1429971132764662059.html;

源码分享

源码分享: 源码分享

如果你觉得这篇文章还不错,请动动小指头点赞、收藏和关注哦!若本文带给你很大帮助,也可以打赏博主一杯可乐ღゝ◡╹)ノ♡
摘繁华版权所有,转发或引用请附上原文链接哦!