Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 3

C# Dialogue handler

Solved! Go to Solution.

Hello,

 

Just to preface this I'm really new to programming - 

 

So I'm trying to create a text adventure using the console in C#.

 

I've made a dialogue handler that changes the colour using `if else` and `if` statements:

 

public static void Dialogue(string message, string color)

		{
			if (color == "red")
			{ Console.ForegroundColor = ConsoleColor.Red; }
			else if (color == "green")
			{ Console.ForegroundColor = ConsoleColor.Green; }
			else if (color == "yellow")
			{ Console.ForegroundColor = ConsoleColor.Yellow; }
			else if (color == "cyan")
			{ Console.ForegroundColor = ConsoleColor.Cyan; }
			else if (color == "blue")
			{ Console.ForegroundColor = ConsoleColor.Blue; }
			else
			{ Console.ForegroundColor = ConsoleColor.White; }

			Console.WriteLine(message);
			Console.ResetColor();
		}

But want it to have expanded capability a little. I'm just not sure how to go about this - I'd like after each dialogue event that it did Console.ReadKey(); as part of it.

 

Also, but if a side question - is there a way to use two functions at the same time for a single piece of text? I wanted to add a typewriter style effect to text so it doesn't just pop up but I'm not sure how to go about that.

 

Thanks in advance, any help is greatly appreciated

 

 

2 Replies
Solution
Commander Lvl 2
Message 2 of 3

Re: C# Dialogue handler

>Also, but if a side question - is there a way to use two functions at the

>same time for a single piece of text?

 

You can call as many functions for a piece of text as you want:

 

string msg = "Here is some text";
typewriter(msg);
Dialogue(msg, "cyan");

 

>I wanted to add a typewriter style effect to text so it doesn't just pop up

>but I'm not sure how to go about that.

I googled "typewriter effect C#" and found a forum thread which shows how you might create a typewriter-like effect.  Or this one. Except both of them are missing a  final "Console.WriteLine();" call to move to the next line.

 

You could add a Console.ReadKey(); call at the end of your Dialogue() function to pause for user response.

 

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Copilot Lvl 2
Message 3 of 3

Re: C# Dialogue handler

Thanks for this, this is definitely what I needed :)