【问题标题】:How can I create Yes/No dialog in C# .NET Framework [duplicate]如何在 C# .NET Framework 中创建是/否对话框 [重复]
【发布时间】:2019-01-09 17:32:51
【问题描述】:

所以我尝试制作一个简单的文字游戏。我想做是/否拨号我试图解决这个问题 2 小时,但我没有找到任何解决我的问题的方法。我完全是初学者,所以我对编码知之甚少。

我试图通过“bool”机器人来实现它,但这不是正确的选择。很明显。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace TEXTRPG

{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Greetings, stranger.");

            Console.ReadKey();

            Console.WriteLine("I've came here to give you a quest.");
            Console.ReadKey();
            Console.WriteLine("Do you accept?");
            //Yes/No
            Console.ReadKey();

【问题讨论】:

  • 你不能有一个控制台应用程序的对话框,那是一个 Windows 窗体应用程序。
  • 使用Console.ReadLine获取文本。
  • 您可以通过控制台请求用户输入并接受是/否文本
  • @JayMason 对话,就像在文字冒险中与角色交谈并进行对话一样。
  • 感谢您的帮助。

标签: c# .net console-application


【解决方案1】:

这是我的示例

do {
        Console.Write("Do you accept? [y/n] ");
        response = Console.ReadKey(false).Key;
        if (response != ConsoleKey.Enter)
            Console.WriteLine();
    } while (response != ConsoleKey.Y && response != ConsoleKey.N);

【讨论】:

    猜你喜欢
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多