超时后Console.Clear()

时间:2013-04-19 16:15:09

标签: c# ascii countdown timespan

我正在用C#控制台开发一个用于家庭作业的游戏。我在ASCII艺术中对游戏的开头做了一些介绍。我想要的是显示这段代码5秒然后去游戏。

我搜索了相关信息并尝试使用Console.Clear(),但不接受TimeSpan参数。

我不是要求你做我的工作,但我寻求指导这样做。

我留下了ASCII艺术的代码,壁纸取自CM Punk“世界上最好的”。

class Programa
{
    static void Main()
    {
        // BEST IN THE WORLD!!!!
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("       Z");
        Console.WriteLine("         Z=");
        Console.ResetColor();
        Console.Write("++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("MZZ.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("$ZZ:.");
        Console.ResetColor();
        Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".ZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".ZZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".ZZZZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".ZZZZZZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.Write("++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".zZZZZZZZZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("                zZZZZZZZZ:.");
        Console.WriteLine("                    zZZZZZ$ZZ:..:7ZZZZZ7$.                                     ");
        Console.WriteLine("                        zZZZZZ. .7.  .$$ZZz                                    ");
        Console.WriteLine("                           zZZZ+:  :Z     ZZ$                                  ");
        Console.WriteLine("     *            *          zZZZZz   Z  Z$Z$             *             *      ");
        Console.WriteLine("*    *    *  *    *    *    zZZZZZZZ   Z$   ZZ       *    *    *   *    *    * ");
        Console.WriteLine("  *******      *******      ZZZ:ZZ.:Z:  Z  Zz          *******       *******   ");
        Console.WriteLine("   *****        ****        ZZ+ZZZZ.  Z7Z$ZZZ:          *****         *****    ");
        Console.WriteLine("  *******      *******      $ZZZI     $Z$$$ZZZZ,       *******       *******   ");
        Console.WriteLine("*    *    *  *    *    *     ZZZZZZ   Z$   ZZ  ZZZZ:.*    *    *   *    *    * ");
        Console.WriteLine("     *            *            zIO,,     :7Z$   7ZZZZ=,   *             *      ");
        Console.WriteLine("                                   $       ZZO    7ZZZZ$+7                     ");
        Console.WriteLine("                                  OZO$.....Z~...7ZZZZI:ZZZZZ+$                 ");
        Console.WriteLine("                                    ZZO:...$ZI.,    7ZZZZ,Z                  ");
        Console.WriteLine("                                   .Z$.OI:?ZOZ,      $77ZZ                     ");
        Console.ResetColor();
        Console.Write("++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".ZZZZZZZ:.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++");
        Console.Write("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".C7ZZI.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++++");
        Console.Write("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write("7ZZ:.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++");
        Console.Write("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.Write(".Z.");
        Console.ResetColor();
        Console.WriteLine("++++++++++++++");
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("                              BEST IN THE WORLD");


    }
}

4 个答案:

答案 0 :(得分:2)

有些选项是Thread.Sleep(5000)Task.Delay(5000)。在控制台应用程序中,使用两者中的哪一个通常无关紧要。在大多数其他情况下,如果您使用的是.NET 4.5或更高版本,我建议使用后者,因为新的.Net异步功能要好得多。

答案 1 :(得分:2)

你可以让当前线程休眠5秒钟:

System.Threading.Thread.Sleep(5000);

答案 2 :(得分:2)

System.Threading.Thread.Sleep(5000);

会暂停你的应用5秒钟。

答案 3 :(得分:2)

只需使用Thread.Sleep暂停执行当前线程一段时间。