我正在製作尋寶遊戲 - 我允許用戶輸入座標 - 如果它包含「寶貝」的「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