Hello,
Below is a simple gun simulator for the console, but everytime I hit spacebar, I have to hit it twice before the next line will pop up in the console. This started happening after I inserted the last 'if' statement in order to reload the gun. Does anyone know what's going on? Can't seem to figure it out. Thanks for any help!
static void Main(string[] args)
{
Console.WriteLine("Press Spacebar to fire the gun. You start with 8 bullets in the mag.\n");
int i = 8;
while (Console.ReadKey(true).Key == ConsoleKey.Spacebar)
{
if (i > 0)
{
i = i - 1;
Console.WriteLine("\nYou now have {0} bullets in the barrel.\n", i);
}
if (i == 0)
{
Console.WriteLine("\nYou have 0 bullets in your pistol! Hit 'r' to reload!\n");
Console.WriteLine("All you hear is a click.\n");
}
if (Console.ReadKey(true).Key == ConsoleKey.R)
{
i = 8;
Console.WriteLine("You now have 8 bullets in your mag.");
}
}
}