BIT-Studio-1 / project-23-1-orangehathackers

project-23-1-orangehathackers created by GitHub Classroom
0 stars 0 forks source link

Make a method to animate text #32

Open Daniel2003Morris opened 1 year ago

Daniel2003Morris commented 1 year ago

we need a method to pass a string to and print it out letter by letter with proper formatting. This also means any text printed out before this method is created will need to be remade into a string and sent to the method.

Mayank-1709 commented 1 year ago

Example:

Here is an example of how we can achieve the desired effect. The sample code has some issue, which needs to be discussed.

Sample Code:

static void Animate(string[] text)
        {
            bool skip = false;
            int windowWidth = Console.WindowWidth;
            foreach(string line in text)
            {
                int leftPadding = (windowWidth - line.Length) / 2;
                if (!skip)
                {
                    for (int i=0; i <= leftPadding; i++)
                    {
                        Console.Write(" ");
                    }
                    foreach (char c in line)
                    {
                        if (Console.KeyAvailable && Console.ReadKey(intercept: true).Key == ConsoleKey.Enter)
                        {
                            skip = true;
                            break;
                        }
                        Console.Write(c);
                        Thread.Sleep(30);   
                    }
                }
                else
                {
                    for (int i = 0; i <= leftPadding; i++)
                    {
                        Console.Write(" ");
                    }
                    Console.Write(line);
                }
                Console.WriteLine();
            }
        }
Mayank-1709 commented 1 year ago

Update:

After the team discussion, it was decided that the above example will not be implemented. We will go through with Daniel's idea. He will give the updated code in the coming days.

Daniel2003Morris commented 1 year ago

Here's an example of how to format the array and send it to the animate method

string[] text = { "You are an archaeologist exploring an ancient excavation site.", "Your mission is to find a long-lost artifact of great power.", "Prepare yourself for an adventure filled with puzzles and mysteries!", "", "Press enter to continue"}; Animate(text);

each line should be in there own quotation marks each string should be separated should be separated by a comma and a line break, to make it more readable an empty string should serve as a line break