求小游戏C#代码

求小游戏C#代码越多越好越多分数越多... 求小游戏C#代码 越多越好 越多分数越多 展开
 我来答
伐木pp工人
2010-09-06 · 超过13用户采纳过TA的回答
知道答主
回答量:80
采纳率:0%
帮助的人:31.2万
展开全部
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;
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友5f36781a6
2010-09-06 · TA获得超过1867个赞
知道小有建树答主
回答量:162
采纳率:0%
帮助的人:111万
展开全部
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;
}
}
}

}}

}}}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
gdutwzh
2010-09-06 · TA获得超过153个赞
知道小有建树答主
回答量:162
采纳率:0%
帮助的人:133万
展开全部
我有个斗地主的,代码就没办法贴了,如果需要,留言,哈
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
mayz411
2010-09-12
知道答主
回答量:11
采纳率:0%
帮助的人:9.3万
展开全部
已经发了..
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式