Just like the way the computer does it in War Games. I've started, but I don't know where to go from here.
static void TypeLine(string line)
{
string output = null;
char[] characters = line.ToCharArray();
for (int i = 0; i < characters.Length; i++)
{
output += characters[i];
Console.Clear();
}
Console.WriteLine(output);
}
My idea was to split the string you wanted it to output, add a character, clear the console, add another, and so on. I got that far, but I don't really know how to make it add, then clear, then add again. Some tips would be nice, or even completed code if you feel like it.
For entering the characters with some delay as others said the best way is use
Thread.Sleep(time)
.but actually there is some more details may you want to add. For example maybe you want to customize the character shown (as you can see in the video you gave us) but in a console windows there is no effect.
Adding these effects is completely another story and that's a little complicated.
How should I create a custom graphical console/terminal on Windows? give you a good vision for what you want ;)
The effect you are looking for is that after each character of the string is written to the console a short delay of about 10 to 50 milliseconds is made, just like in this code:
In the code above, I create a string that has a line break in it (
Environment.NewLine
). Afterwards I use anforeach
loop to run through every character of that string and write it to the console one by one. After each character, the thread is put to sleep for 30 milliseconds (Thread.Sleep
) so that is just works again after that time span.If you have any further questions, please feel free to ask.
The easiest way may be to Sleep() between characters. Something like this: