我正在用C#編寫我的第一個文本冒險遊戲,我只是想知道如何循環回到以前的if語句。 例如:如何轉回以前的if語句?
if (x == 2 || y == 3)
{
//do this
if (z > 3 || v = 6)
{
//do this
}
}
我會用什麼來讓它從嵌套去,如果以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語句?
你應該展示一個實際的用例,用於你想做的任何事情。 – poke
來吧......你必須提供更多的信息,而不僅僅是展示2'If'語句..你是否熟悉遞歸或while循環或for循環不能告訴你剛剛發佈的內容。 – MethodMan
我的appologies。將更新更具體的信息 –