绘制一个简单的刽子手设计链接到我在c#中的错误猜测

时间:2013-12-14 21:50:40

标签: c#

我希望根据用户输入的错误答案,使用键盘中的字符显示一个简单的刽子手设计。这些不正确的答案每次都会给刽子手画一个新作品,虽然我不确定如何做到这一点。我让我的程序功能在显示正确的答案并循环回到一个新单词之前循环进行10次猜测。

我问的问题是我不知道如何在c#中对刽子手进行直观表示,以及如何将其链接到我现有的代码,只根据不正确的猜测来绘制刽子手的特定部分。我该怎么做?

代码如下。

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);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我不太确定您打算如何使用ASCII艺术绘制刽子手,但您可以创建一个包含10个“图片”作为字符串的字符串数组,然后在适当时显示相应的字符串。

你可以像这样创建一个数组:

var pictures = new[]{":-)", ":-|", ":-(", "x.x", etc. };

然后

count++;

// display it here

Console.WriteLine(pictures[count]);

Console.Write("\n\nPlease enter your guess  : ");