【发布时间】:2018-03-03 12:46:59
【问题描述】:
我有一个带整数的或运算符 (||),但由于某种原因,它给了我一个错误。整数是位置。我想跟踪玩家的位置,这样我就可以在一段代码中控制所有的动作。看起来像 if (location == (1 || 2 || 3) 的行给了我错误。
Actions:
Console.WriteLine("");
Console.Write("What should i do? ");
string move = Console.ReadLine();
if (move.Contains("north"))
{
if (location == (1 || 2 || 3))
{
Console.WriteLine("There is a cliff here I cant climb up!");
}
}
else if (move.Contains("east"))
{
if (location == (3 || 6 || 9))
{
Console.WriteLine("There is a cliff here I cant climb up!");
}
}
else if (move.Contains("south"))
{
if (location == (7 || 8 || 9))
{
Console.WriteLine("There is a cliff here I cant climb up!");
}
}
else if (move.Contains("west"))
{
if (location == (1 || 2 || 3))
{
Console.WriteLine("There is a cliff here I cant climb up!");
}
}
else if (move.Contains("grab"))
{
if (location == (6))
{
Console.WriteLine("I don't have time for apples!");
}
else if (location == (8))
{
Console.WriteLine("It's locked!");
}
else if (location == (1 ||2 || 4 || 5 || 7 || 9))
{
Console.WriteLine("There is nothing to grab!");
}
else if (location == (3))
{
Console.WriteLine("I grabbed the key.");
bool key = true;
}
}
else if (move.Contains("use"))
{
}
感谢您的帮助。
【问题讨论】:
-
而
if (location == (6))可以变成if (location == 6) -
请务必在发布问题之前查看语言文档。这是一个微不足道的 sintax 错误