【发布时间】:2016-11-05 14:17:09
【问题描述】:
我正在使用 C# 制作我的第一个文本冒险游戏,我只是想知道如何循环回到之前的 if 语句。 例如:
if (x == 2 || y == 3)
{
//do this
if ( z > 3 || v = 6)
{
//do this
}
}
我会用什么让它从嵌套的 if 到顶部的 if 语句?
编辑:更具体地说:
//start
System.Console.WriteLine("You awake in a stupor. The sun blinds you as you roll over to breathe the new day.");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine("To your (west), you see a volcanic mountain, with a scraggly, dangerous looking path.");
System.Console.WriteLine(" ");
System.Console.WriteLine("In the (east), you see a thick forrest. there is nothing visible past the treeline.");
System.Console.WriteLine(" ");
System.Console.WriteLine("Looking (south), you see a long winding road that seems to have no end.");
System.Console.WriteLine(" ");
System.Console.WriteLine("Hearing a sound of celebration, you look to the (north). There appears to be a city, with a celebration going on.");
System.Console.WriteLine(" ");
System.Console.WriteLine(" ");
System.Console.WriteLine("Which direction would you like to travel?");
string direction1 = Convert.ToString(Console.ReadLine());
//first decision (north)
if (direction1 == "north" || direction1 == "North")
{
Console.WriteLine("You proceed towards the north, only to be stopped by a guard:");
Console.WriteLine("Guard: 'the kingdom of al'arthar is off limits to outsiders today, its the queens birthday, and the kingdom is packed full");
Console.WriteLine(" ");
Console.WriteLine(" ");
Console.WriteLine("you can either try to (swindle) the guard, or (leave). What will you do?");
string guardConvo1 = Convert.ToString(Console.ReadLine());
例如,如果有人在这种情况下向北旅行,然后想回去。与其重新编码前一个 if 语句,我如何让它循环回到前一个 if 语句?
【问题讨论】:
-
你应该为你想做的任何事情展示一个实际的用例。
-
来吧,伙计..您必须提供更多信息,而不仅仅是显示 2 个
If语句..您是否熟悉递归或 while 循环或 for 循环无法告诉您要做什么你刚刚发布的内容.. -
我的道歉。将更新更具体的信息
标签: c#