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



在我的中期CYA游戏中,你会遇到左右两个楼梯。你可以选择去哪一个,右边让你前进,左边(最终(把你送回来,因为它被阻止了。基于我现有的知识,我不知道如何做到这一点。

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

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

您可以使用go to语句。

电脑:非常容易使用。

关于go to

相关内容

  • 没有找到相关文章

最新更新