繁体   English   中英

选择错误答案后如何告诉我的程序 go 回到某个点?

[英]How do I tell my program to go back to a certain point after the wrong answer is selected?

在我的期中 CYA 游戏中,您会遇到左右两个楼梯。 你可以选择你 go 到哪一个,右边让你前进,左边(最终)让你返回,因为它被阻止了。 我不知道如何根据我已经拥有的东西来做到这一点。

    List<string> itemsList1 = new List<string>();

    
    string input1;
    string input2;
    public FirstSteps()
    {
        Console.WriteLine("Unfortunately for us, we have to start at the bottom of the castle, unless you have a catapult or a grappling hook, but I don't suppose you have either of those do you.\n");
        

    }
    
    public void Populate()
    {
        contentArray1[0] = "See that key lying there? Think we should grab it?\n Type Yes or No.";
        contentArray1[1] = "Really? You don't want to grab the key thats just sitting there? Your loss.";
        contentArray1[2] = "Wow, isn't this a cliche. 2 staircases, the wrtiers really must be getting bored. Anyways, we going for the right or the left?\n Type Right or Left";
        contentArray1[3] = "This staircase is blocked, try again";
        contentArray1[4] = "Theres a chest up here, wonder if that key can open it, wanna try?\n Type Yes or No.";
        contentArray1[5] = "You need the key to open the chest, duh.";
    }

    public void KeyEvent()
    {
        Console.WriteLine(contentArray1[0]);
        input1 = Console.ReadLine();
        input1 = input1.ToLower();

        if (input1 == "yes")
        {
            Console.WriteLine("Right, probably a good idea.");
            itemsList1.Add("dirty key");
        }
        else
        {
            Console.WriteLine(contentArray1[1]);
        }
                       
    }

    public void StepsEvent()
    {
        Console.WriteLine(contentArray1[2]);
        input2 = Console.ReadLine();
        input2 = input2.ToLower();

        if (input2 == "left")
        {
           
            Console.WriteLine(contentArray1[3]);
        }
        if (input2 == "right")
        {
            Console.WriteLine("Right one it is.");
            Console.WriteLine(contentArray1[4]);
        }
    }

这是我正在使用的(大部分)我的 class。 当我开始使用 input2 时,问题就出现了,根据我对数组的设置和 if 语句,我不知道如何做到这一点,所以当左边的 if 语句触发时,它说 contentArray1[3],然后将您送回决策。 我想我需要一个循环,但我不知道把它放在哪里。

您可以使用go to声明。

个人电脑:非常容易使用。

go to

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM