How to make Console Applications Respond Without Prompt
So, I want to create a roguelike video game in C# for a console application. The game will use procedurally generated environments that features ASCII characters and weapons created with WriteAt() methods. My main concern is this: How can I make it so that the interface will respond without the user having to press enter? In most console application programs, the interface will only respond when the user presses enter. However, I downloaded an executable version of Rogue for Windows and the directional controls allowed the user to move instantaneously without using the enter key. How can I make my program do this? I'm using Visual C# 2010 Express.
Re: How to make Console Applications Respond Without Prompt
you could use Console.ReadKey(false) to read the single key pressed.
If key is not one of the arrows keys, you should loop and read again - or ask if user wants to exit. If the key is an arrow,move.
Console.Readkey does not need the enter key to let you step on.
static void Main(string args)
Console.WriteLine("Press H for Humans, D for Dragons, K for Keys - Any other key to step on - try with ann arrow key (to see how you could read it)");
ConsoleKeyInfo theKey= Console.ReadKey(false);
switch (theKey.KeyChar )
case 'H': case 'h' :
Console.WriteLine("Humans are around");
case 'D': case 'd':
Console.WriteLine("Dragons are coming");
case 'K': case 'k':
Console.WriteLine("You do not find the key");
Console.WriteLine("key was " + theKey.Key.ToString());
Console.WriteLine("Any key to Exit");
theKey = Console.ReadKey(false);
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.