0

I'm trying to do a project with regard to displaying two separate text-animation in one line which shall display like this image example

I am using inheritance for this. I, however, can't display them in one line. I need assistance aligning them in the same line as the image provided.

Here is the screenshot of the code. Code screenshot I can't seem to upload the code. public void Egg() {

        Console.Write("     ___" +
            "\n    /   \\" +
            "\n   |’    |" +
            "\n    \\___/");
        //return;

    }

    public void Cat()
    {
        Console.Write("\n                                      _,'|             _.-''``-...___..--';" +
                          "\n                                     /_ \\'.      __..-' ,      ,--...--'''" +
                          "\n                                   <\\    .`--'''       `     /'" +
                          "\n                                    `-';'               ;   ; ;" +
                          "\n                            __...--''     ___...--_..'  .;.'" +
                          "\n                          (,__....----'''       (,..--''   " +
                          "");
        //return;
    }
    public class My_Calculation : Program
    {
        static void Main(string[] args)
        {
            My_Calculation demo = new My_Calculation();
            demo.Egg();
            demo.Cat();


            Console.Read();
        }
    }

I am open to suggestions if there is a better way of solving this. Thanks in advance!

1 Answers1

1

You won't be able to align them when you print one after the other. The egg has new line characters in it which means that something printed after it will always be underneath it.

The simple solution to this is to print the cat and the egg at the same time i.e. have the cat and egg in the same string.

Update:

To Achieve what (I think) you want to do, all you need is to have a token that you replace with whitespace to make the cat move closer to the egg e.g.:

public static class CatAndEgg
{
    private const string ReplacementString = "[SPACES]";
    private const string Image = @"        [SPACES]             _,'|             _.-''``-...___..--';
    [SPACES]          /_ \\'.      __..-' ,      ,--...--'''
___  [SPACES]        <\\    .`--'''       `     /'
/   \\[SPACES]          `-';'               ;   ; ;
|’    |[SPACES]  __...--''     ___...--_..'  .;.'
\\___/ [SPACES](,__....----'''       (,..--'' ";

    public static void PrintImageWithSpaces(int numberOfSpaces)
    {
        string spaces = new(' ', numberOfSpaces);
        Console.Write(Image.Replace(ReplacementString, spaces));
        Console.Write(Environment.NewLine);
    }

    public static void DoAnimation()
    {
        PrintImageWithSpaces(20);
        Task.Delay(200).Wait();
        PrintImageWithSpaces(15);
        Task.Delay(200).Wait();
        PrintImageWithSpaces(10);
        Task.Delay(200).Wait();
        PrintImageWithSpaces(5);
        Task.Delay(200).Wait();
        PrintImageWithSpaces(0);
    }
}

The method PrintImageWithSpaces() prints the cat and the egg with the specified number of spaces between them. By staring off with x number of spaces and then reducing the number of spaces each time you call PrintImageWithSpaces(), the cat moves closer to the egg.

Calling DoAnimation() would provide an example of the animation that you want.

i.e.:

public static void Main()
{
    //Animation Example
    CatAndEgg.DoAnimation();

    //Manually Move cat closer to egg
    CatAndEgg.PrintImageWithSpaces(10);
    Task.Delay(200).Wait();
    CatAndEgg.PrintImageWithSpaces(5);
    Task.Delay(200).Wait();
    CatAndEgg.PrintImageWithSpaces(0);
}

Note: the time delays are added in the above code so you can see the prints gradually added but you wouldn't need them if you print each time a user inputs a wrong answer.

YungDeiza
  • 3,128
  • 1
  • 7
  • 32
  • Had that thought too. However, I'm trying to create a console quiz app that let the cat moves whenever the inputted answer is wrong. I want to lessen the code usage. – Mr. Skadoosh Oct 04 '22 at 12:02
  • Updated my answer with a code solution to what I think you want to do – YungDeiza Oct 04 '22 at 13:24
  • I can't seem to comprehend, sir. Plus it's not working on my console app. A further explanation or revise would be greatly appreciated. – Mr. Skadoosh Oct 05 '22 at 13:33
  • Tried to expand further and provide more detail - I'm also trying to grasp what you actually want based on your description and comments - this is probably the best I can do – YungDeiza Oct 05 '22 at 14:06
  • How about for example I want to add a fence on the egg. Should I just use a bracket like how the spaces are done? Since this is a console quiz game, I'm trying to achieve a guard the egg idea by implementing protection on the (4) sides of the egg. 4 fence equates to 4 correct answers. \n____________ \n| __ | \n| / \ | \n| |’ | | \n| \ ___ / | \n-------------------- – Mr. Skadoosh Oct 06 '22 at 11:02
  • That's a new problem so best to start a new question for that. Make sure to provide the required details clearly. – YungDeiza Oct 06 '22 at 11:06
  • Here is the link of my project idea. https://drive.google.com/file/d/1HlEa_NSJ9sopT3z1RaeNC84vpG5PywOo/view?usp=sharing – Mr. Skadoosh Oct 06 '22 at 11:07
  • The provided link shows what I am trying to achieve sir – Mr. Skadoosh Oct 06 '22 at 12:03
  • It would be a similar concept, but you would just need to have some form of tokens that you replace for each fence/wall. – YungDeiza Oct 06 '22 at 12:19
  • what form of tokens, sir? i'm very baffled :((( – Mr. Skadoosh Oct 06 '22 at 12:29
  • By token I mean a string that you can recognise and replace (```ReplacementString```) e.g.[Spaces]. Basically use the same technique for moving the cat to the egg but with different tokens/strings. – YungDeiza Oct 06 '22 at 13:03
  • It worked when I did the fence. However, when both space and fence is applied, it is not working. – Mr. Skadoosh Oct 07 '22 at 12:21
  • public static void PrintImageWithUpperFence(int upperFence, int numberOfSpace) { string uFence = new string('-', upperFence), uspaces = new string(' ', numberOfSpace); Console.Write(Image.Replace(UpperFenceString, uFence), Image.Replace(ReplacementString, uspaces)); Console.Write(Environment.NewLine); } – Mr. Skadoosh Oct 07 '22 at 12:22
  • I've used this. i've declared a new const called UpperFenceString. The space part is not working :((( – Mr. Skadoosh Oct 07 '22 at 12:23
  • CatAndEgg.PrintImageWithUpperFence(9, 10); – Mr. Skadoosh Oct 07 '22 at 12:24
  • I suggest you start a new question for that as it's moved very far from the original problem. – YungDeiza Oct 07 '22 at 12:25
  • Added one. Thanks. I appreciate your kindness. https://stackoverflow.com/questions/73994102/how-to-substitute-a-space-and-special-characters-in-c – Mr. Skadoosh Oct 08 '22 at 03:21
  • I need your help so bad :(((((( – Mr. Skadoosh Oct 08 '22 at 12:59