dimanche 15 mars 2020

Console.ReadKey seems to be reading the wrong key?

I'm just starting out so I'm in the middle of writing my first console application from scratch. I have this line of code, when I hit d it correctly takes me to the next step and sets disadvantage to true, however if I hit a it executes the else statement for some reason. Any ideas what the cause is?

Console.WriteLine("Press the A key for advantage, or the D key for disadvantage");
var rollType = Console.ReadKey();
Console.WriteLine(System.Environment.NewLine);
if (rollType.Key == ConsoleKey.A)
{
    advantage = true;
}
if (rollType.Key == ConsoleKey.D)
{
    disadvantage = true;
}
else
{
    Console.WriteLine("Invalid Input");
    StartApp();
}

Aucun commentaire:

Enregistrer un commentaire