我正在制作寻宝游戏 - 我允许用户输入坐标 - 如果它包含“宝贝”的“t”,那么它们将获胜。但我想添加一些东西,以便它能检查他们输入的内容,如果t在他们猜测的1个半径范围内 - 它会说“你很热”。或者如果“t”大于1个元素,则表示“你很冷”。查看二维数组中的相邻值
我想不出我能做到这一点的最佳方式。我试过的东西,如
if (Board[Row+1,Column] == 't' || Board[Row+1,Column+1] == 't' etc etc etc)
{
Console.WriteLine("You are hot.");
}
else
{
Console.Writeline("You are cold.");
}
但这似乎并没有为我工作,我不能用链表又那么我想解决这个问题,而无需使用它们。
这是应该算出来的代码的一部分。
string HotOrCold = "";
if (Board[Row, Column] != 'x')
{
Board[Row, Column] = 'm';
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Clear();
if() // Here Is Where It Should Figure It Out
Console.WriteLine("Uh-oh! You haven't found the treasure, try again!");
Console.WriteLine("You are {0}.", HotOrCold);
Console.ForegroundColor = ConsoleColor.Gray;
wonGame = false;
PrintBoard(Board);
SaveGame(username, ref Board);
}
我也试过一个嵌套for循环 - 但也许我没有正确使用。
我真的建议改变你的if语句使用'开关{}也case'关于如何使用调试器读取了并在您的代码中设置断点 – MethodMan
我会读取switch语句,我知道如何设置断点 - 我必须更多地了解调试器。 –
使用switch语句.. – MethodMan