求用C#编写的猜数字的小游戏

来源:百度知道 编辑:UC知道 时间:2024/05/11 15:54:51
有难度等级之分(猜三个数还是四个数),能记录不同级别前六名(所猜次数)的人名字.

using System;
namespace guess
{
class readyguess //用户输入参数
{
public int formatinput()
{
int i = 0;
try
{
i = Convert.ToInt16(Console.ReadLine());
if (i == 0)
System.Environment.Exit(-1);
return i;
}
catch (FormatException)
{
Console.WriteLine("输入参数有误,请重新输入:");
return 0;
}

}

public int Rannumber() //由计算机产生一个随机数(0~100)的类
{
Random Ran;
Ran = new Random();
int i = Convert.ToInt32(Ran.NextDouble() * 100);
return i;
}

public void Commentguess(int count) //根据游戏者的次数给出评价
{

switch (count)
{
case 1: Console.WriteLine("而且你非常聪明!猜了{0}次就对了!", count);
break;
case 2: Console.WriteLine("而且你非常聪明!猜了{0}次就对了!", count);
break;
case 3: Console.WriteLine("而且你非常聪明!猜了{0}次就对了!", count);
break;
case 4: Console.WriteLine("