I am making a C# console text-based game, and because I wanted it to look more old-school, I've added an effect so that any text (descriptions, tutorials, dialogues) looks like it's being typed, and it looks like this:
public static int pauseTime = 50;
class Writer
{
public void WriteLine(string myText)
{
int pauseTime = MainClass.time;
for (int i = 0; i < myText.Length; i++)
{
Console.Write(myText[i]);
System.Threading.Thread.Sleep(pauseTime);
}
Console.WriteLine("");
}
}
But then I thought that this might be annoying and I thought about adding an option to skip the effect and make all the text appear at once. So I chose the Enter key to be the "skip" key, and it makes the text appear at once, but pressing the enter key also creates a new text line, scrambling the text.
So I want to somehow disable user input, so that the user cannot write anything in the console. Is there a way to, for example, disable the command prompt (and by command prompt I don't mean cmd.exe, but the flashing "_" underscore sign)?
Instead of just sleeping between Writes, you could listen for key input using this class (as suggested here):
In your loop:
I have just handwritten this and not checked it, so if it doesn't work let me know
I think what you want is
Console.ReadKey(true)
which will intercept the pressed key and won't display it.Source: MSDN Article