向各位大哥大姐求一点C#编写的小游戏源代码!!(最好新颖一点的)

感谢大家的关注,不过有一点小小的问题,这源代码怎么不能运行啊?usingSystem.Linq;这一句是不是少什么东西啊?... 感谢大家的关注,不过有一点小小的问题,这源代码怎么不能运行啊?using System.Linq;这一句是不是少什么东西啊? 展开
 我来答
poseidon___
2009-03-17 · TA获得超过284个赞
知道小有建树答主
回答量:266
采纳率:100%
帮助的人:0
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace NumberPuzzle
{
class Program
{
/// <summary>
/// Num Puzzle
/// ^^**
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string numPazzle = string.Empty;
string numLength = string.Empty;
int count = 0;
int countMax = 0;

Console.WriteLine("How long do you want?[0<n<11] \"Suggestion : 4\"");

while (true)
{
numLength = Console.ReadLine();
if (IsNum(numLength))
{
countMax = Convert.ToInt32(numLength);
if (countMax > 10)
{
Console.WriteLine("Re-inpt due to n>10");
continue;
}
break;
}
else
{
Console.WriteLine("Re-inpt, input is not a num:");
continue;
}
}

while (count < countMax)
{
string strA = GetNum();
if (numPazzle.IndexOf(strA) != -1)
{
continue;
}
numPazzle += strA;
count++;
}

while (true)
{
string input = string.Empty;
string results = string.Empty;
Console.WriteLine("Input what you guess:");
input = Console.ReadLine();

if (!IsNum(input))
{
Console.WriteLine("Re-inpt, input is not a num:");
continue;
}

if (input.Length != countMax)
{
Console.WriteLine("The length of input is error");
continue;
}

if (IsDup(input))
{
Console.WriteLine("Input is a dup num");
continue;
}
results = CompareNum(input, numPazzle);
if (results.Split('-')[0].Equals(numPazzle.Length.ToString()))
break;

Console.WriteLine("Results: A-{0} B-{1}", results.Split('-')[0], results.Split('-')[1]);
}
Console.WriteLine("Win! The num is {0}", numPazzle);
Console.ReadKey();
}

public static string GetNum()
{
Random sSeed = new Random();
Random seed = new Random(sSeed.Next());
return seed.Next(10).ToString();
}

public static string CompareNum(string actualStr, string expectedStr)
{
int a = 0;
int b = 0;
string results = string.Empty;
for (int i = 0; i < actualStr.Length; i++)
{
if (expectedStr.IndexOf(actualStr[i]) != -1)
{
b++;
}
if (expectedStr[i].Equals(actualStr[i]))
{
a++;
b--;
}
}
results = a.ToString() + "-" + b.ToString();
return results;
}

public static bool IsDup(string input)
{
bool result = false;
foreach (char aStr in input)
{
if (input.IndexOf(aStr) != input.LastIndexOf(aStr))
{
result = true;
break;
}
}
return result;
}

public static bool IsNum(string numInput)
{
bool result = false;
Regex reg = new Regex(@"^-?\d+$");
result = reg.IsMatch(numInput);
return result;
}
}
}
CMD 猜数字
小我猪是
2009-03-17 · TA获得超过773个赞
知道答主
回答量:23
采纳率:0%
帮助的人:10.8万
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace NumberPuzzle
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式