我试图编写一个简单的文本冒险。当我开始编写用户可以前往的方向时,我意识到用户可以输入“东北”、“西南”等,所以我认为我应该为他们制作案例。
我的问题是当我在命令行中输入“north east”时,case5“north east”没有运行。
class Branches
{
static void main(string[] args)
{
Branch2();
}
public static void Branch2()
{
Console.WriteLine("");
Console.WriteLine("(North ,East ,South ,West)");
string input = Console.ReadLine();
bool case1 = input.Contains("north");
bool case2 = input.Contains("east");
bool case3 = input.Contains("south");
bool case4 = input.Contains("west");
bool case5 = input.Contains("north") && input.Contains("east");
//Console.ReadLine();
int CaseId;
if (case1)
CaseId = 1;
else if (case2)
CaseId = 2;
else if (case3)
CaseId = 3;
else if (case4)
CaseId = 4;
else if (case5)
CaseId = 5;
else
CaseId = 0;
switch (CaseId)
{
case 1:
Console.WriteLine("");
Console.WriteLine("you head north");
break;
case 2:
Console.WriteLine("");
Console.WriteLine("you head east");
break;
case 3:
Console.WriteLine("");
Console.WriteLine("you head south");
break;
case 4:
Console.WriteLine("");
Console.WriteLine("you head west");
break;
case 5:
Console.WriteLine("");
Console.WriteLine("you head north east");
break;
default:
Console.WriteLine("enter a valid direction");
break;
}
}
}
}