我正在 C# 上的 Visual Studio 上制作游戏(在控制台中)。这是关于对话的,你可以用2个选项来回答它们,一个键(用于回答第一个问题)是1,另一个是2。问题是当你按一个键时,你不能按另一个键更多,我的意思是,如果你按1,你就不能按2,反之亦然。
static void Main(string[] args)
{
Console.WriteLine("Press 1 or 2 please...");
//I know there are some errors in this code, i'm new at c#
ConsoleKeyInfo number1;
do
{
number1 = Console.ReadKey();
Console.WriteLine("Number 1 was pressed");
//This is the 1st answer
}
while (number1.Key != ConsoleKey.D1);
ConsoleKeyInfo number2;
//The problem is that when I already pressed D1 (1), I shouldn't be
//able to press D2 (2). And if I press D2 (2), I shoundn´t be able
//to press D1 (1).
do
{
number2 = Console.ReadKey();
Console.WriteLine("Number 2 was pressed");
//This is the 2nd answer
}
while (number2.Key != ConsoleKey.D2);
Console.ReadLine();
}