大学第一个项目!(双色球)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
public static int camputerblue()
{
Random sj = new Random();
Console.WriteLine("蓝球产生的随机数为");
int lan = sj.Next(1, 34);
Console.WriteLine(lan);
return lan;
}
public static int[] camputerred()
{
Random sj = new Random();
Console.WriteLine("红球产生的随机数为");
int count = 0;
int h = 0;
int[] s = new int[6];
for (int i = 0; i < s.Length; i++)
{
h = sj.Next(1, 34);
for (int j = 0; j < s.Length; j++)
{
if (s[j] == h)
{
count++;
}
}
if (count > 0)
{
i--;
}
else
{
s[i] = h;
}
Console.WriteLine(s[i]);
}
return s;
}
public static int[] peoplered()
{
//用户输入的红球 red
int[] red = new int[6];
for (int i = 0; i < red.Length; i++)
{
Console.WriteLine("请输入你所猜的第{0}红球号(1--34)", i + 1);
red[i] = int.Parse(Console.ReadLine());
for (int j = 0; j < i; j++)
{
if (red[i] == red[j])
{
i--;
break;
}
if (red[i] > 34)
{
i--;
}
}
}
return red;
}
public static void Add(int a, int b)
{
switch (b)
{
case 0:
switch (a)
{
case 0: Console.WriteLine("没中奖"); break;
case 1: Console.WriteLine("六等奖B"); break;
case 2: Console.WriteLine("五等奖B"); break;
case 3: Console.WriteLine("四等奖B"); break;
case 4: Console.WriteLine("三等奖B"); break;
case 5: Console.WriteLine("二等奖B"); break;
case 6: Console.WriteLine("一等奖B"); break;
}
break;
case 1:
switch (a)
{
case 0: Console.WriteLine("六等奖A"); break;
case 1: Console.WriteLine("五等奖A"); break;
case 2: Console.WriteLine("四等奖A"); break;
case 3: Console.WriteLine("三等奖A"); break;
case 4: Console.WriteLine("二等奖A"); break;
case 5: Console.WriteLine("一等奖A"); break;
case 6: Console.WriteLine("特等奖"); break;
}
break;
}
}
static void Main(string[] args)
{
Console.WriteLine("******************************");
Console.WriteLine("欢迎进入双色球系统");
Console.WriteLine("*******************************");
for (int cw = 0; cw < 3; cw++)
{
Console.WriteLine("请输入账号");
string zhanghao = Console.ReadLine();
Console.WriteLine("请输入密码");
string mima = Console.ReadLine();
if (zhanghao == "admin" && mima == "123456")
{
cw = 3;
int jixu = 0;
while (jixu < 3)
{
Console.WriteLine("欢迎进入双色球选号界面(每个号限玩三次!!)");
Console.WriteLine("请选择你所要选的选号方式");
Console.WriteLine("1.自主选号");
Console.WriteLine("2.随机选号");
int xuanhao = int.Parse(Console.ReadLine());
//红球系统产生的随机数 sj 用数组s2[]储存
/*Random sj = new Random();
Console.WriteLine("红");
int count = 0;
int h = 0;
int[] s = new int[6];
for (int i = 0; i < s.Length; i++)
{
h = sj.Next(1, 34);
for (int j = 0; j < s.Length; j++)
{
if (s[j] == h)
{
count++;
}
}
if (count > 0)
{
i--;
}
else
{
s[i] = h;
}
Console.WriteLine(s[i]);
}*/
//蓝球系统产生的随机数 lan
if (xuanhao == 1)
{
/*//用户输入的红球 red
int[] red = new int[6];
for (int i = 0; i < red.Length; i++)
{
Console.WriteLine("请输入你所猜的第{0}红球号(1--34)", i + 1);
red[i] = int.Parse(Console.ReadLine());
for (int j = 0; j < i; j++)
{
if (red[i] == red[j])
{
i--;
break;
}
if (red[i] > 34)
{
i--;
}
}
}*/
//用户输入的蓝球 l
Console.WriteLine("请输入你所猜的蓝球号(1--34)");
int l = int.Parse(Console.ReadLine());
Thread.Sleep(1000);
int[] red = peoplered();
int[] s = camputerred();
Thread.Sleep(1000);
int blue = camputerblue();
/*Random sj = new Random();
Console.WriteLine("蓝");
int lan = sj.Next(1, 34);
Console.WriteLine(lan);*/
//判断
int a = 0, b = 0;
for (int i = 0; i < red.Length; i++)
{
for (int j = 0; j < red.Length; j++)
{
if (red[j] == s[i])//用户输入的红球号与系统随机号进行比较
{
a++;
}
}
}
if (l == blue)//比较篮球号
{
b++;
}
Console.WriteLine("你猜中红球{0}个,猜中蓝球{1}个,", a, b);
Add(a, b);
/*switch (b)
{
case 0:
switch (a)
{
case 0: Console.WriteLine("没中奖"); break;
case 1: Console.WriteLine("六等奖B"); break;
case 2: Console.WriteLine("五等奖B"); break;
case 3: Console.WriteLine("四等奖B"); break;
case 4: Console.WriteLine("三等奖B"); break;
case 5: Console.WriteLine("二等奖B"); break;
case 6: Console.WriteLine("一等奖B"); break;
}
break;
case 1:
switch (a)
{
case 0: Console.WriteLine("六等奖A"); break;
case 1: Console.WriteLine("五等奖A"); break;
case 2: Console.WriteLine("四等奖A"); break;
case 3: Console.WriteLine("三等奖A"); break;
case 4: Console.WriteLine("二等奖A"); break;
case 5: Console.WriteLine("一等奖A"); break;
case 6: Console.WriteLine("特等奖"); break;
}
break;
}*/
}
if (xuanhao == 2)
{
/*//红球随机选号产生的随机数sj1 用数组 s1[]储存
Random sj1 = new Random();
Console.WriteLine("红球随机选号产生的号码为");
int count1 = 0;
int h1 = 0;
int[] s1 = new int[6];
for (int i = 0; i < s1.Length; i++)
{
h1 = sj1.Next(1, 34);
for (int j = 0; j < s1.Length; j++)
{
if (s1[j] == h1)
{
count1++;
}
}
if (count1 > 0)
{
i--;
}
else
{
s1[i] = h1;
}
Console.WriteLine(s1[i]);
}*/
Thread.Sleep(1000);
int[] s1 = camputerred();
Thread.Sleep(1000);
int[] s = camputerred();
//蓝球随机选号产生的随机数 lan1
Thread.Sleep(1000);
int lan1 = camputerblue();
//判断
int blue = camputerblue();
int c = 0, d = 0;
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < s.Length; j++)
{
if (s[j] ==s1[i])
{
c++;
}
}
}
if (blue == lan1)
{
d++;
}
Console.WriteLine("你猜中红球{0}个,猜中蓝球{1}个,", c, d);
Add(c, d);
}
Console.WriteLine("是否继续买号,继续:1,退出:0");
int jix = int.Parse(Console.ReadLine());
if (jix == 1)
{
continue;
}
if (jix == 0)
{
Console.WriteLine("退出程序成功");
break;
}
} jixu++;
}
else
{
Console.WriteLine("密码错误,请重新输入");
}
if (cw == 2)
{
Console.WriteLine("错误三次退出程序");
}
}
}
}
}

浙公网安备 33010602011771号