簡體   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