I am new to C# so this might be really dumb and I am doing it all wrong but... I am trying to write a text adventure and I need to be able to slow type each letter out and wrap each word to 80 chars, so it looks like a smooth paragraph when there is a chunk of text.
public static void Wrap()
{
var words = text.Split(' ');
var lines = words.Skip(1).Aggregate(words.Take(1).ToList(), (l, w) =>
{
if (l.Last().Length + w.Length >= 80)
l.Add(w);
else
l[l.Count - 1] += " " + w;
return l;
});
}
To do this I just change the var text to whatever I want to write then call on Wrap()
var text = "text"
Wrap();
That works, and is all good - maybe inefficient, but I have a separate thing that makes it type out each char with a 40 millisecond delay.
public static void MW(string str)
{
foreach (char c in str)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(c);
Thread.Sleep(40);
}
}
I just do
MW("Text");
To do this.
So overall, I need it to slow type, wrap the words neatly and change the colour. Is this possible. Sorry if this is inefficient or wrong, I don't know much about this language yet.
I tried to combine them on my own, but I don't have enough experience and could not figure it out.