// See https://aka.ms/new-console-template for more information
//六红一白彩票模拟器
//.NET 6.0 框架
//功能描述 :输入7个数字(六红一白),系统随机产生7个数,对比之后给出是否中奖
// MakeRandom()部分代码粘贴于博客,部分修改根据评论 https://blog.csdn.net/li951527983/article/details/86580279?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.pc_relevant_default&utm_relevant_index=5
int[] redrandem;
redrandem = MakeRandom();
Array.Sort(redrandem);
int k = writerandamnumber();
//Console.WriteLine("中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
switch (compare(inputred(), redrandem, inputwrite(), k))
{
case 0:
Console.WriteLine("未中奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 1:
Console.WriteLine("恭喜你,中了一等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 2:
Console.WriteLine("恭喜你,中了二等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 3:
Console.WriteLine("恭喜你,中了三等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 4:
Console.WriteLine("恭喜你,中了四等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 5:
Console.WriteLine("恭喜你,中了五等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
case 6:
Console.WriteLine("恭喜你,中了六等奖,中奖号码为\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], k);
return;
}
//Array.Sort(randamnumber());
//int[] redrandem ;
//redrandem = randamnumber();
//Console.WriteLine("中奖号码为{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", redrandem[0], redrandem[1], redrandem[2], redrandem[3], redrandem[4], redrandem[5], writerandamnumber());
//判断白球号码是否合法 writeball
static int inputwrite()
{
//白球
a: Console.WriteLine("请输入1-16之间的数字");
int j = int.Parse(Console.ReadLine());
if (j < 0 || j > 16)
{
Console.WriteLine("输入错误,请重新输入");
goto a;
}
else
{
return j;
}
}
//输入号码 redball
static int[] inputred()
{
//红球
int[] redball = new int[6];
for (int i = 0; i < 6;)
{
Console.WriteLine("请输入1-33之间的号码:");
int j = int.Parse(Console.ReadLine());
bool again = Array.IndexOf(redball, j) > 0;
if (again == false) //false 说明数组中没有这个元素
{
if (j >= 1 && j <= 33)
redball[i++] = j;
else
Console.WriteLine("超出取值范围。");
}
else
{
Console.WriteLine("本数字已经输入过,请重新输入");
continue;
}
}
return redball;
}
//随机生成redball
int[] MakeRandom()
{
int MaxValue = 33, Number = 6;
int[] itemIds = new int[Number]; //新建数组,大小为6
int[] temp = new int[MaxValue]; //新建数组,大小为 33
for (int i = 0; i < MaxValue; i++)
temp[i] = i+1; //temp[] 赋值 0 1 2 3 4 5 ....32
for (int i = 0; i < Number; i++)
{
Random rand = new Random();
int r = rand.Next(0, MaxValue);
itemIds[i] = temp[r]; //给数组 itemIds[i] 赋值,r是随机数
int j = r;
temp[j] = temp[MaxValue - 1];
//for (int j = r ; j < MaxValue - 1 ; j++)
//{
// temp[j] = temp[j + 1]; //取过的数据被覆盖掉
//}
MaxValue--;
}
return itemIds;
}
//随机生成writeball
static int writerandamnumber()
{
Random rand = new Random();
int mad = rand.Next(1, 16);
return mad;
}
//判断是否中奖
static int compare(int[] redball, int[] mad , int write , int writeinput)
{
int winningnumber = 0 ;
int winningnumberWrite =0;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
if (redball[i] == mad[j])
{ winningnumber++; }
}
}
if (write == writeinput)
winningnumberWrite = 1;
return rule(winningnumber, winningnumberWrite);
}
static int rule(int winnum, int winnumwrite)
{
if (winnum == 0 || winnum == 1)
return 0; //未中奖
else if (winnum == 0 && winnumwrite == 1)
return 6;
else if (winnum == 1 && winnumwrite == 1)
return 6;
else if (winnum == 2 && winnumwrite == 1)
return 6; //六等奖
else if (winnum == 3 && winnumwrite == 1)
return 5;
else if (winnum == 4 && winnumwrite == 0)
return 5; //五等奖
else if (winnum == 4 && winnumwrite == 1)
return 4;
else if (winnum == 5 && winnumwrite == 0)
return 4; //四等奖
else if (winnum == 5 && winnumwrite == 1)
return 3; //三等奖
else if (winnum == 6 && winnumwrite == 0)
return 2; //二等奖
else if (winnum == 6 && winnumwrite == 1)
return 1;
else
return -1; //一等奖
}