一、新建一个控制应用
二、将下面所附代码复制后粘贴到新建项目中,将原来的覆盖掉
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Game_GuessNumber
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("---------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("----------------------------------------欢迎参加猜数字游戏-----------------------------------------------------------");
Console.WriteLine("---------------------------------------------------------------------------------------------------------------------");
Console.WriteLine("----------------------------------游戏模式有三种模式:简单、困难、噩梦-----------------------------------------------");
Console.Write("请输入您要挑战的模式(简单、困难、噩梦,回车结束):");
//难度系数
string NanDu = "简单";
string NanDu1 = "困难";
string NanDu2 = "噩梦";
//取值范围系数
int Range=0;
//允许输入次数
int count = 0;
//已输入次数
int aly = 0;
string Str = Console.ReadLine();
if (Str==NanDu)
{
Range = 200;
count = 6;
}
else if (Str==NanDu1)
{
Range = 500;
count = 6;
}
else if (Str==NanDu2)
{
Range = 1500;
count = 7;
}
else
{
Range = 10000;
count = 7;
}
//取值范围
Random round = new Random();
int Scope = round.Next(0,Range);
//范围、次数确定
Console.WriteLine("---------------------------------------------------------------------------------------------------------");
Console.WriteLine("玩家您好,您选择的难度为:{0},猜数的范围为:0-{1},猜数的机会一共有:{2}次,祝您玩得开心",Str,Range,count);
Console.WriteLine("---------------------------------------------------------------------------------------------------------");
//成功系数
bool Flag;
//玩家输入值系数
int UserT;
//外挂
int Acount=3;
//玩家输入
while (true)
{
Console.Write("请输入您猜的数字:");
string UserStr = Console.ReadLine();
aly++;
if (UserStr != null && Regex.IsMatch(UserStr, @"^\d+$"))
{
UserT = int.Parse(UserStr);
if (UserT != Scope)
{
if (UserT > Scope)
{
Console.WriteLine("很抱歉,您输入的数字大了,可以尝试输小一点,您还剩{0}次机会", count - aly);
}
else if (UserT < Scope)
{
if (aly!=count)
{
Console.WriteLine("很抱歉,您输入的数字小了,可以尝试输大一点,您还剩{0}次机会", count - aly);
}
else
{
Console.WriteLine("很抱歉,您机会用完,即将失败!");
}
}
}
else if (UserT == Scope)
{
if (aly == 1)
{
Console.WriteLine("一次命中,天选之人!恭喜你!");
}
else if (aly > 1 && aly < 3)
{
Console.WriteLine("您的运气和实力是王者级别,一共用了{0}次机会", aly);
}
else
{
Console.WriteLine("恭喜你!成功通过!");
}
Flag = true;
break;
}
if (aly == count)
{
Console.WriteLine("\n");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("很抱歉,您用光了所有的{0}次机会。在这最后关头,你可以虔诚祈愿",count);
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine("祈愿池:直接过关、增加挑战次数、钝角");
Console.Write("请说出你的愿望:");
string UserL = Console.ReadLine();
if (UserL == "增加挑战次数")
{
count += Acount;
Console.WriteLine("我感受到了你虔诚的愿望,欢迎回来,你现在还有{0}次机会", count - aly);
}
else if (UserL == "直接过关")
{
Console.WriteLine("我感受到了你虔诚的愿望,本次游戏底数为:{0};有没有猜到呢", Scope);
Flag = true;
break;
}
else
{
Console.WriteLine("很抱歉您的机会已用光,期待你下一次的精彩表现!");
Flag = false;
break;
}
}
}
else
{
Console.WriteLine("对不起,您输入的不是正整数,浪费了一次机会,目前只有{0}次机会",count-aly);
}
}
if (Flag)
{
Console.WriteLine("恭喜成功过关!!!");
Console.ReadLine();
}
else
{
Console.WriteLine("很遗憾,你失败了,再接再厉!");
Console.ReadLine();
}
}
}
}
三、 鼠标右键点击项目,然后生成
四、找到你生成的的exe程序
五、 转发给朋友,双击打开,即可游玩
你,学会了吗