using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 猜数字游戏
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
//让游戏处于一个死循环状态 让用户多挑战几次
while (true)
{
int randomNumber = random.Next(1, 101);
//记录 猜了多少次了
int count = 0;
while (count < 5)
{
count++;
Console.WriteLine("请输入数字(1-100)");
int selectNumber = int.Parse(Console.ReadLine());
if (randomNumber == selectNumber)
{
Console.WriteLine("恭喜您,猜对了");
switch (count)
{
case 1:
Console.WriteLine("神一样的人物");
break;
case 2:
case 3:
Console.WriteLine("一般人");
break;
case 4:
case 5:
Console.WriteLine("险过,努力吧骚年!");
break;
default:
break;
}
break;
}
else if (randomNumber > selectNumber)
{
Console.WriteLine("猜小了");
}
else
{
Console.WriteLine("猜大了");
}
if (count >= 5)
{
Console.WriteLine("对不起,您挑战失败,正确的数字是:{0}.不服再战", randomNumber);
}
}
Console.WriteLine("退出(Y/y),继续请按任意键...");
string exit = Console.ReadLine();
if (exit == "Y" || exit=="y")
{
Environment.Exit(0);
}
}
}
}
}
猜数字游戏
最新推荐文章于 2024-08-26 01:32:35 发布