C# 绘制一个简单的刽子手设计链接到我在c中的错误猜测
我希望根据用户输入的错误答案,使用键盘上的字符来显示一个简单的刽子手设计。这些不正确的答案每次都会给刽子手带来新的东西,尽管我不知道怎么做。在显示正确答案并循环回一个新词之前,我让我的程序函数循环10次猜测 我要问的问题是,我不知道如何在c语言中对刽子手进行可视化表示,以及如何将其与我现有的代码相链接,以便仅根据错误的猜测绘制刽子手的特定部分。我该怎么做 代码如下C# 绘制一个简单的刽子手设计链接到我在c中的错误猜测,c#,C#,我希望根据用户输入的错误答案,使用键盘上的字符来显示一个简单的刽子手设计。这些不正确的答案每次都会给刽子手带来新的东西,尽管我不知道怎么做。在显示正确答案并循环回一个新词之前,我让我的程序函数循环10次猜测 我要问的问题是,我不知道如何在c语言中对刽子手进行可视化表示,以及如何将其与我现有的代码相链接,以便仅根据错误的猜测绘制刽子手的特定部分。我该怎么做 代码如下 namespace ConsoleApplication9 { class Program { st
namespace ConsoleApplication9
{
class Program
{
static string RandomWord()
{
Random rnd = new Random();
int response = rnd.Next(1, 4);
string randWord = "";
switch (response)
{
case 1:
randWord = "dog";
break;
case 2:
randWord = "robot";
break;
case 3:
randWord = "fish";
break;
case 4:
randWord = "continue";
break;
}
return randWord;
}
static void Main(string[] args)
{
string value = "";
int count = 0;
int gameLoop = 0;
string inData;
Console.WriteLine("Welcome to Hangman here is the first word");
do
{
count = 0;
value = RandomWord();
char[] newValue = new char[value.Length];
for (int i = 0; i < newValue.Length; i++)
{
newValue[i] = '_';
}
for (int i = 0; i < newValue.Length; i++)
{
Console.Write(newValue[i] + " ");
}
do
{
count++;
Console.Write("\n\nPlease enter your guess : ");
char input = (Console.ReadLine().ToCharArray()[0]);
for (int i = 0; i < value.Length; i++)
{
if (value[i] == input)
{
newValue[i] = input;
}
}
for (int x = 0; x < newValue.Length; x++)
{
Console.Write(newValue[x] + " ");
}
string s = (value);
string t = new string(newValue);
int c = string.Compare(s, t);
if (c == 0)
{
count = 10;
Console.WriteLine("\n\nCongratulations you guessed the word {0}", value);
}
} while (count < 10);
string Wrong = (value);
string Wrong2 = new string(newValue);
int gameOver = string.Compare(Wrong, Wrong2);
if (gameOver != 0)
{
Console.WriteLine("\n\nGame Over! the correct word was {0}", value);
}
Console.WriteLine("Would you like to go again? if so press 1 or 0 to exit");
inData = Console.ReadLine();
gameLoop = Convert.ToInt32(inData);
}
while (gameLoop == 1);
}
}
}
我不太清楚你打算如何使用ASCII艺术画刽子手,但你可以创建一个字符串数组,包含10幅图片作为字符串,然后在适当的时候显示相应的图片 您可以这样创建一个数组:
var pictures = new[]{":-)", ":-|", ":-(", "x.x", etc. };
然后
count++;
// display it here
Console.WriteLine(pictures[count]);
Console.Write("\n\nPlease enter your guess : ");
你在寻求什么样的帮助?这不是你想要的吗?你看到了什么行为?如果您能更准确地回答您的问题,而不是期望我们了解您的想法,这将对我们有所帮助:。谢谢,这似乎是正确的事情,加上放在哪里真的很有帮助,我知道我不应该发表评论,但非常感谢:好的,很抱歉再次发布,我尝试了您建议的答案,我明白了,唯一的问题是如何让上一个数组顶部与当前数组顶部一起显示?你说的数组顶部是什么意思?对不起,我拼错了。我基本上是问如何显示数组中以前的图形,因此如果他们第四次收到错误的字母,它将显示图片数组中的第0个元素,第1、第2和第3个元素。您可以使用for循环:for int idx=0;idx