我有一個循環,裏面有一個開關盒,它基本上是一個用戶界面,讓用戶選擇yes,現在用左右箭頭繼續遊戲。Console.ReadKey()在while循環中自行循環
我還添加了一個Console.Beep()給用戶一些反饋。由於某種原因,一旦遊戲結束(遊戲中使用的箭頭(其蛇))選擇yes和no保持開關和我聽到蜂鳴約10〜20次,然後停止。 有誰知道原因? 這是代碼:
while (true)
{
Console.Clear();
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~\n\n~~~~~~~~You Lost!~~~~~~~~\n\n~~~~~~~~~~~~~~~~~~~~~~~~~\nYour score was: " + SnakeBody.Count);
Console.WriteLine("\nDo you want to continue?\n\n " + (Continue ? ">YES/No" : " Yes/>NO"));
switch (Console.ReadKey().Key)
{
case ConsoleKey.LeftArrow:
if (!Continue)
{
Console.Beep(SoundFrequency, SoundLength);
Continue = true;
}
continue;
case ConsoleKey.RightArrow:
if (Continue)
{
Console.Beep(SoundFrequency, SoundLength);
Continue = false;
}
continue;
case ConsoleKey.Enter:
Console.Beep(SoundFrequency + 200, SoundLength);
if (Continue)
SnakeGame();
break;
default: continue;
}
break;
}
糟糕的語言 - 我刪除了我的評論。 :) –